Skip to content

Commit

Permalink
fix(apis_entities,core): add templatetag for generating entitymenu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
b1rger committed May 29, 2024
1 parent 782b5c8 commit 481ded5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 16 additions & 0 deletions apis_core/apis_entities/templatetags/apis_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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"]
Expand Down
7 changes: 3 additions & 4 deletions apis_core/core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@
<div class="dropdown-menu" aria-labelledby="navbarDropdown">

{% block entities-menu-items %}
{% entities_content_types as entities %}
{% for content_type in entities %}
<a class="dropdown-item"
href="{% url 'apis:generic:list' content_type %}">{{ content_type|model_meta:"verbose_name_plural"|capfirst }}</a>
{% entities_verbose_name_plural_listview_url as entities %}
{% for verbose_name_plural, list_url in entities %}
<a class="dropdown-item" href="{{ list_url }}">{{ verbose_name_plural|capfirst }}</a>
{% endfor %}
{% endblock entities-menu-items %}

Expand Down

0 comments on commit 481ded5

Please sign in to comment.