Skip to content

Commit

Permalink
cap relations in edit views
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Nov 5, 2024
1 parent 049396d commit d5a2383
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h3 class="text-center mt-5">Beziehungen</h3>
{% block relations %}
{% for obj in right_card %}
{% if obj.1.data|length > 0 %}
<h4>{{ obj.0 }} {% if obj.5 %}<a class="apis-{{ obj.5 }}" title="Gehe zu {{ object }}–{{ obj.0 }} Relationen" href="{{ obj.4 }}"><i class="bi bi-box-arrow-up-right" aria-hidden="true"><span class="visually-hidden">Gehe zu {{ object }} - {{ obj.5 }} Relationen</span></i></a> {% if obj.6 %} <span class="fs-6 fw-light">aus technischen Gründen werden hier nur 50 von {{ obj.7 }} Relationen angezeigt </span> {% endif %}{% endif %}</h4>
<h4>{{ obj.0 }} {% if obj.5 %}<a class="apis-{{ obj.5 }}" title="Gehe zu {{ object }}–{{ obj.0 }} Relationen" href="{{ obj.4 }}"><i class="bi bi-box-arrow-up-right" aria-hidden="true"><span class="visually-hidden">Gehe zu {{ object }} - {{ obj.5 }} Relationen</span></i></a> {% if obj.6 %} <span class="fs-6 fw-light">An dieser Stelle werden nur 50 von {{ obj.7 }} Beziehungen angezeigt. Alle Beziehungen <a title="Gehe zu {{ object }}–{{ obj.0 }} Relationen" href="{{ obj.4 }}"><strong>hier</strong></a></span> {% endif %}{% endif %}</h4>

<div id="tab_{{ obj.2 }}" class="mb-5">
{% render_table obj.1 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h4>Entitäten zusammenführen</h4>
<h3 class="text-center">Bearbeiten der Verbindungen</h3>
{% for obj in right_card %}
<div class="pt-2">
<h4>{{ obj.0 }}</h4>
<h4>{{ obj.0 }} {% if obj.5 %} <span class="fs-6 fw-light">zeigt nur 20 von {{ obj.6 }} Beziehungen, klicke <a href="{{ obj.4 }}">hier</a> für alle Relationen</span> {% endif %}</h4>
<div id="tableDiv__{{ obj.2 }}">
{% render_table obj.1 %}
</div>
Expand Down
17 changes: 14 additions & 3 deletions apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,30 @@ def get(self, request, *args, **kwargs):
rel.get_related_entity_classb().__name__.lower(),
]
prefix = "{}{}-".format(match[0].title()[:2], match[1].title()[:2])
table = get_generic_relations_table(
relation_class=rel, entity_instance=instance, detail=False
)
title_card = ""
if match[0] == match[1]:
title_card = entity.title()
dict_1 = {"related_" + entity.lower() + "a": instance}
dict_2 = {"related_" + entity.lower() + "b": instance}
objects = rel.objects.filter(Q(**dict_1) | Q(**dict_2))
link_to_relations = f"{rel.get_listview_url()}?target={pk}"
else:
link_to_relations = f"{rel.get_listview_url()}?source={pk}"
if match[0].lower() == entity.lower():
title_card = match[1].title()
else:
title_card = match[0].title()
dict_1 = {"related_" + entity.lower(): instance}
objects = rel.objects.filter(**dict_1)
object_count = objects.count()
disable_sort = False
if object_count > 20:
if object_count > 20:
objects = objects[:20]
disable_sort = True
table = get_generic_relations_table(
relation_class=rel, entity_instance=instance, detail=False, disable_sort=disable_sort
)
tb_object = table(data=objects, prefix=prefix)
tb_object_open = request.GET.get(prefix + "page", None)
RequestConfig(request, paginate={"per_page": 10}).configure(tb_object)
Expand All @@ -63,6 +71,9 @@ def get(self, request, *args, **kwargs):
tb_object,
"".join([x.title() for x in match]),
tb_object_open,
link_to_relations,
disable_sort,
object_count
)
)
form = get_entities_form(entity.title())
Expand Down

0 comments on commit d5a2383

Please sign in to comment.