-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show relations of nested places in Place detail page
closes #49
- Loading branch information
Showing
6 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% extends "apis_core/apis_entities/e53_place_detail.html" %} | ||
|
||
{% block relations-include %} | ||
{% include "relations/list_relations_include_tabs.html" %} | ||
{% include "relations/place_list_relations_include_tabs.html" %} | ||
{% endblock relations-include %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% extends "apis_core/apis_entities/abstractentity_form.html" %} | ||
|
||
{% block relations-include %} | ||
{% include "relations/list_relations_include_tabs.html" with edit=True %} | ||
{% include "relations/place_list_relations_include_tabs.html" with edit=True %} | ||
{% endblock relations-include %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% if record.forward %} | ||
<a href="{{ record.subj.get_absolute_url }}" style="{{ highlight_style }}"> | ||
{{ record.subj }} | ||
</a> | ||
{% else %} | ||
<a href="{{ record.obj.get_absolute_url }}" style="{{ highlight_style }}"> | ||
{{ record.obj }} | ||
</a> | ||
{% endif %} |
9 changes: 9 additions & 0 deletions
9
apis_ontology/templates/relations/place_list_relations_include_tabs.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends "relations/list_relations_include_tabs.html" %} | ||
|
||
{% load nested_relations %} | ||
|
||
|
||
{% block display-relations %} | ||
{% relations_from_place from_obj=object include_places_within=True as relations %} | ||
{{ block.super }} | ||
{% endblock display-relations %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
from django import template | ||
from django.utils.safestring import mark_safe | ||
from django.contrib.contenttypes.models import ContentType | ||
from apis_ontology.models import Place, PlaceIsLocatedWithinPlace | ||
from apis_core.relations.templatetags.relations import relations_from | ||
|
||
register = template.Library() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@register.simple_tag | ||
def relations_from_place( | ||
from_obj, relation_type: ContentType = None, include_places_within=False | ||
): | ||
|
||
def locations_contained_in(place_id): | ||
nested_places = [ | ||
rel.subj_object_id | ||
for rel in set( | ||
(PlaceIsLocatedWithinPlace.objects.filter(obj_object_id=place_id)) | ||
) | ||
] | ||
for p in nested_places: | ||
nested_places.extend(locations_contained_in(p)) | ||
|
||
return nested_places | ||
|
||
rels = relations_from(from_obj, relation_type) | ||
if not include_places_within: | ||
return rels | ||
|
||
nested_locs = locations_contained_in(from_obj.pk) | ||
if not nested_locs: | ||
return rels | ||
|
||
nested_rels = [] | ||
for nested_loc in nested_locs: | ||
nested_rels.extend( | ||
relations_from(Place.objects.get(pk=nested_loc), relation_type) | ||
) | ||
|
||
return [*rels, *nested_rels] |