Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(apis_entities): use verbose_name_plural in the entity list menu #776

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apis_core/apis_entities/templatetags/apis_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django import template
from apis_core.utils import caching
from apis_core.utils.helpers import triple_sidebar
from django.contrib.contenttypes.models import ContentType
from apis_core.apis_entities.models import AbstractEntity

register = template.Library()

Expand Down Expand Up @@ -29,6 +31,26 @@ def entities_list_links():
return entities_links


def is_entity(content_type: ContentType):
model_class = content_type.model_class()
return model_class is not None and issubclass(model_class, AbstractEntity)


@register.simple_tag
def entities_content_types():
"""
Retrieve all models which inherit from AbstractEntity class
and return their ContentType.
"""
entities = list(
filter(
lambda content_type: is_entity(content_type),
ContentType.objects.all(),
)
)
return entities


@register.simple_tag(takes_context=True)
def object_relations(context, detail=True):
obj = context["object"]
Expand Down
6 changes: 3 additions & 3 deletions apis_core/core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
<div class="dropdown-menu" aria-labelledby="navbarDropdown">

{% block entities-menu-items %}
{% entities_list_links as entities_links %}
{% for ent in entities_links %}
{% entities_content_types as entities %}
{% for content_type in entities %}
<a class="dropdown-item"
href="{% url 'apis:apis_entities:generic_entities_list' ent.0 %}">{{ ent.1 }}</a>
href="{% url 'apis:generic:list' content_type %}">{{ content_type|model_meta:"verbose_name_plural" }}</a>
{% endfor %}
{% endblock entities-menu-items %}

Expand Down
Loading