Просмотр исходного кода

Expose regsitry in templates using existing context processor for settings

Jeremy Stretch 5 лет назад
Родитель
Сommit
dd9fc4173d

+ 0 - 10
netbox/extras/plugins/context_processors.py

@@ -1,10 +0,0 @@
-from extras.registry import registry
-
-
-def plugin_menu_items(request):
-    """
-    Retrieve and expose all plugin registered navigation menu items.
-    """
-    return {
-        'plugin_menu_items': registry['plugin_menu_items']
-    }

+ 1 - 2
netbox/netbox/settings.py

@@ -325,8 +325,7 @@ TEMPLATES = [
                 'django.template.context_processors.media',
                 'django.template.context_processors.media',
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
                 'django.contrib.messages.context_processors.messages',
-                'utilities.context_processors.settings',
-                'extras.plugins.context_processors.plugin_menu_items',
+                'utilities.context_processors.settings_and_registry',
             ],
             ],
         },
         },
     },
     },

+ 1 - 1
netbox/templates/inc/nav_menu.html

@@ -504,7 +504,7 @@
                         </li>
                         </li>
                     </ul>
                     </ul>
                 </li>
                 </li>
-                {% if plugin_menu_items %}
+                {% if registry.plugin_menu_items %}
                     {% include 'inc/plugin_menu_items.html' %}
                     {% include 'inc/plugin_menu_items.html' %}
                 {% endif %}
                 {% endif %}
             </ul>
             </ul>

+ 1 - 1
netbox/templates/inc/plugin_menu_items.html

@@ -2,7 +2,7 @@
 <li class="dropdown">
 <li class="dropdown">
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Plugins <span class="caret"></span></a>
     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Plugins <span class="caret"></span></a>
     <ul class="dropdown-menu">
     <ul class="dropdown-menu">
-        {% for section_name, menu_items in plugin_menu_items.items %}
+        {% for section_name, menu_items in registry.plugin_menu_items.items %}
             <li class="dropdown-header">{{ section_name }}</li>
             <li class="dropdown-header">{{ section_name }}</li>
             {% for menu_item in menu_items %}
             {% for menu_item in menu_items %}
                 <li{% if menu_item.permissions and not request.user|has_perms:menu_item.permissions %} class="disabled"{% endif %}>
                 <li{% if menu_item.permissions and not request.user|has_perms:menu_item.permissions %} class="disabled"{% endif %}>

+ 5 - 2
netbox/utilities/context_processors.py

@@ -1,10 +1,13 @@
 from django.conf import settings as django_settings
 from django.conf import settings as django_settings
 
 
+from extras.registry import registry
 
 
-def settings(request):
+
+def settings_and_registry(request):
     """
     """
-    Expose Django settings in the template context. Example: {{ settings.DEBUG }}
+    Expose Django settings and NetBox registry stores in the template context. Example: {{ settings.DEBUG }}
     """
     """
     return {
     return {
         'settings': django_settings,
         'settings': django_settings,
+        'registry': registry,
     }
     }