-
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.
Merge pull request #15 from acdh-oeaw/relations
Relations
- Loading branch information
Showing
6 changed files
with
336 additions
and
138 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
41 changes: 41 additions & 0 deletions
41
apis_ontology/templates/apis_core/apis_entities/abstractentity_detail.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,41 @@ | ||
{% extends "apis_core/apis_entities/abstractentity.html" %} | ||
{% load django_tables2 %} | ||
{% load apis_templatetags %} | ||
{% load apiscore %} | ||
{% load relationsng %} | ||
|
||
{% block col-zero %} | ||
<div class="card"> | ||
<div class="card-body">{% include "generic/partials/object_table.html" %}</div> | ||
</div> | ||
{% endblock col-zero %} | ||
|
||
{% block col-one %} | ||
<h4>Relations</h4> | ||
{% related_entity_types as related_entity_types %} | ||
<div class="container"> | ||
<!-- Nav tabs --> | ||
<ul class="nav nav-tabs"> | ||
{% for ent_type in related_entity_types %} | ||
|
||
<li class="nav-item"> | ||
<a class="nav-link {% if forloop.first %}active{% endif %}" data-toggle="tab" | ||
href="#reltype{{forloop.counter0}}">{{ent_type |model_meta:"verbose_name" | title}}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<!-- Tab panes --> | ||
<div class="tab-content"> | ||
{% for ent_type in related_entity_types %} | ||
<div class="tab-pane container {% if forloop.first %}active{% endif %}" id="reltype{{forloop.counter0}}"> | ||
{% entity_relations with_type=ent_type as entity_relations %} | ||
{% render_table entity_relations %} | ||
</div> | ||
{% endfor %} | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
{% endblock col-one %} |
31 changes: 31 additions & 0 deletions
31
apis_ontology/templates/apis_entities/partials/entity_relations_multiple_cards.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,31 @@ | ||
{% load django_tables2 %} | ||
{% load apis_templatetags %} | ||
{% load apiscore %} | ||
{% load relationsng %} | ||
|
||
<h4>Relations</h4> | ||
{% related_entity_types as related_entity_types %} | ||
<div class="container"> | ||
<!-- Nav tabs --> | ||
<ul class="nav nav-tabs"> | ||
{% for ent_type in related_entity_types %} | ||
|
||
<li class="nav-item"> | ||
<a class="nav-link {% if forloop.first %}active{% endif %}" data-toggle="tab" | ||
href="#reltype{{forloop.counter0}}">{{ent_type |model_meta:"verbose_name" | title}}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<!-- Tab panes --> | ||
<div class="tab-content"> | ||
{% for ent_type in related_entity_types %} | ||
<div class="tab-pane container {% if forloop.first %}active{% endif %}" id="reltype{{forloop.counter0}}"> | ||
{% entity_relations with_type=ent_type as entity_relations %} | ||
{% render_table entity_relations %} | ||
</div> | ||
{% endfor %} | ||
|
||
</div> | ||
|
||
</div> |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from django import template | ||
import logging | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models import Q | ||
from apis_core.relations.models import Relation | ||
from apis_ontology.models import TibScholRelationMixin | ||
from itertools import chain | ||
|
||
from apis_ontology.tables import RelationsTableEdit | ||
from django.db.models.query import QuerySet | ||
from django_tables2 import RequestConfig | ||
from django_tables2.tables import table_factory | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.simple_tag(takes_context=True) | ||
def related_entity_types(context): | ||
entity = context["object"] | ||
content_type = ContentType.objects.get_for_model(entity) | ||
models = TibScholRelationMixin.__subclasses__() | ||
relavent_models = set() | ||
for m in models: | ||
if ContentType.objects.get_for_model(m.subj_model) == content_type: | ||
relavent_models.add(ContentType.objects.get_for_model(m.obj_model)) | ||
|
||
if ContentType.objects.get_for_model(m.obj_model) == content_type: | ||
relavent_models.add(ContentType.objects.get_for_model(m.subj_model)) | ||
|
||
logger.debug("RELAVENT MODELS: %s", relavent_models) | ||
return relavent_models | ||
|
||
|
||
@register.simple_tag(takes_context=True) | ||
def entity_relations(context, with_type): | ||
entity = context["object"] | ||
content_type = ContentType.objects.get_for_model(entity) | ||
models = TibScholRelationMixin.__subclasses__() | ||
forward_relations = [] | ||
reverse_relations = [] | ||
for m in models: | ||
if ( | ||
ContentType.objects.get_for_model(m.subj_model) == content_type | ||
and ContentType.objects.get_for_model(m.obj_model) == with_type | ||
): | ||
forward_relations.extend(m.objects.filter(subj=entity)) | ||
logger.debug(m.objects.filter(subj=entity)) | ||
|
||
if ( | ||
ContentType.objects.get_for_model(m.obj_model) == content_type | ||
and ContentType.objects.get_for_model(m.subj_model) == with_type | ||
): | ||
reverse_relations.extend(m.objects.filter(obj=entity)) | ||
logger.debug(m.objects.filter(subj=entity)) | ||
|
||
table = RelationsTableEdit | ||
|
||
return table(forward_relations + reverse_relations) | ||
|
||
|
||
# + table( | ||
# reverse_relations, reverse=True | ||
# ) |
Oops, something went wrong.