From 481ded530e6ac06bdf0ea9ad7c3c56b3e15cf669 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Mon, 27 May 2024 10:21:24 +0200 Subject: [PATCH] fix(apis_entities,core): add templatetag for generating entitymenu This introduces `entities_verbose_name_plural_listview_url` templatetag, which returns all entities verbose names together with their list uri, sorted in alphabetical order. This is then used in the core template for the main entities menu. Closes: #860 --- .../templatetags/apis_templatetags.py | 16 ++++++++++++++++ apis_core/core/templates/base.html | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apis_core/apis_entities/templatetags/apis_templatetags.py b/apis_core/apis_entities/templatetags/apis_templatetags.py index fea4ea9bb..02006011f 100644 --- a/apis_core/apis_entities/templatetags/apis_templatetags.py +++ b/apis_core/apis_entities/templatetags/apis_templatetags.py @@ -5,6 +5,8 @@ from django.contrib.contenttypes.models import ContentType from apis_core.apis_entities.models import AbstractEntity +from apis_core.apis_entities.utils import get_entity_classes + register = template.Library() @@ -51,6 +53,20 @@ def entities_content_types(): return entities +@register.simple_tag +def entities_verbose_name_plural_listview_url(): + """ + Return all entities verbose names together with their list uri, sorted in alphabetical order + USED BY: + * `core/base.html` + """ + ret = { + entity._meta.verbose_name_plural: entity.get_listview_url() + for entity in get_entity_classes() + } + return sorted(ret.items()) + + @register.simple_tag(takes_context=True) def object_relations(context, detail=True): obj = context["object"] diff --git a/apis_core/core/templates/base.html b/apis_core/core/templates/base.html index 0993ed10b..4fc4d89f4 100644 --- a/apis_core/core/templates/base.html +++ b/apis_core/core/templates/base.html @@ -109,10 +109,9 @@