'safe' loading of links

This commit is contained in:
Matthias 2021-11-11 13:00:20 +01:00
parent 36591a5f6e
commit fa36bcdbca
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,7 @@
"""
from django.conf import settings as djangosettings
from django import template
from django.urls import reverse
from common.models import InvenTreeSetting
@ -35,3 +36,12 @@ def navigation_enabled(*args, **kwargs):
if djangosettings.TESTING:
return True
return InvenTreeSetting.get_setting('ENABLE_PLUGINS_NAVIGATION')
@register.simple_tag()
def safe_url(view_name, *args, **kwargs):
""" safe lookup for urls """
try:
return reverse(view_name, args=args, kwargs=kwargs)
except:
return None

View File

@ -70,7 +70,10 @@
</a>
<ul class='dropdown-menu'>
{% for nav_item in plugin.navigation %}
<li><a href="{% url nav_item.link %}" class="dropdown-item"><span class='{{nav_item.icon}} icon-header'></span>{{nav_item.name}}</a>
{% safe_url nav_item.link as nav_link %}
{% if nav_link %}
<li><a href="{{ nav_link }}" class="dropdown-item"><span class='{{nav_item.icon}} icon-header'></span>{{nav_item.name}}</a>
{% endif %}
{% endfor %}
</ul>
</li>