Sfoglia il codice sorgente

Get menu header via apps.get_config

Jeremy Stretch 5 anni fa
parent
commit
16b8a45ed6
1 ha cambiato i file con 3 aggiunte e 7 eliminazioni
  1. 3 7
      netbox/extras/plugins/__init__.py

+ 3 - 7
netbox/extras/plugins/__init__.py

@@ -1,8 +1,7 @@
 import collections
-import importlib
 import inspect
 
-from django.apps import AppConfig
+from django.apps import AppConfig, apps
 from django.template.loader import get_template
 
 from extras.registry import registry
@@ -178,11 +177,8 @@ def register_nav_menu_links():
     responses = register_nav_menu_link_classes.send('registration_event')
     for receiver, response in responses:
 
-        # Import the app config for the plugin to get the name to be used as the nav menu section text
-        module = importlib.import_module(receiver.__module__.split('.')[0])
-        default_app_config = getattr(module, 'default_app_config')
-        module, app_config = default_app_config.rsplit('.', 1)
-        app_config = getattr(importlib.import_module(module), app_config)
+        # Derive menu section header from plugin name
+        app_config = apps.get_app_config(receiver.__module__.split('.')[0])
         section_name = getattr(app_config, 'verbose_name', app_config.name)
 
         if not isinstance(response, list):