From fa36bcdbca22153e58066678c7bd46426d945a85 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 11 Nov 2021 13:00:20 +0100 Subject: [PATCH] 'safe' loading of links --- InvenTree/part/templatetags/plugin_extras.py | 10 ++++++++++ InvenTree/templates/navbar.html | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/templatetags/plugin_extras.py b/InvenTree/part/templatetags/plugin_extras.py index c5e86a6900..51a115b67e 100644 --- a/InvenTree/part/templatetags/plugin_extras.py +++ b/InvenTree/part/templatetags/plugin_extras.py @@ -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 diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index cd2a2a0a56..02f7b2e6b7 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -70,7 +70,10 @@