From 06a08dcf6e981dd09f0c7f469410805d49ba9d18 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 23 May 2023 16:05:12 +0200 Subject: [PATCH] allow plugins to add navs --- cookbook/templates/base.html | 13 ++++++++++--- cookbook/templatetags/custom_tags.py | 10 +++++++++- recipes/settings.py | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 39dc51a3..0efbdd5d 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -9,7 +9,7 @@ {% endblock %} - + @@ -50,7 +50,7 @@ @@ -323,6 +323,12 @@ {% trans 'Overview' %} {% endif %} + {% plugin_dropdown_nav_templates as plugin_dropdown_nav_templates %} + {% for pn in plugin_dropdown_nav_templates %} + + {% include pn %} + {% endfor %} + {% trans 'Markdown Guide' %} @@ -349,6 +355,7 @@ + {% message_of_the_day request as message_of_the_day %} {% if message_of_the_day %}
@@ -413,7 +420,7 @@ localStorage.setItem('STATIC_URL', "{% base_path request 'static_base' %}") localStorage.setItem('DEBUG', "{% is_debug %}") localStorage.setItem('USER_ID', "{{request.user.pk}}") - + window.addEventListener("load", () => { if ("serviceWorker" in navigator) { navigator.serviceWorker.register("{% url 'service_worker' %}", {scope: "{% base_path request 'base' %}" + '/'}).then(function (reg) { diff --git a/cookbook/templatetags/custom_tags.py b/cookbook/templatetags/custom_tags.py index b958999a..5ade2985 100644 --- a/cookbook/templatetags/custom_tags.py +++ b/cookbook/templatetags/custom_tags.py @@ -16,7 +16,7 @@ from cookbook.helper.mdx_attributes import MarkdownFormatExtension from cookbook.helper.mdx_urlize import UrlizeExtension from cookbook.models import Space, get_model_name from recipes import settings -from recipes.settings import STATIC_URL +from recipes.settings import STATIC_URL, PLUGINS register = template.Library() @@ -132,6 +132,14 @@ def is_debug(): def markdown_link(): return f"{_('You can use markdown to format this field. See the ')}{_('docs here')}" +@register.simple_tag +def plugin_dropdown_nav_templates(): + templates = [] + for p in PLUGINS: + if p['nav_dropdown']: + templates.append(p['nav_dropdown']) + return templates + @register.simple_tag def bookmarklet(request): diff --git a/recipes/settings.py b/recipes/settings.py index 5f61ea56..d05d0373 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -147,6 +147,8 @@ try: 'base_url': plugin_class.base_url, 'bundle_name': plugin_class.bundle_name if hasattr(plugin_class, 'bundle_name') else '', 'api_router_name': plugin_class.api_router_name if hasattr(plugin_class, 'api_router_name') else '', + 'nav_main': plugin_class.nav_main if hasattr(plugin_class, 'nav_main') else '', + 'nav_dropdown': plugin_class.nav_dropdown if hasattr(plugin_class, 'nav_dropdown') else '', } PLUGINS.append(plugin_config) except Exception: