mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 00:36:11 -06:00
Closes #10659: Import signals.py from Plugin
Uses the importlib.import_module function from Python to import the signals module. This registers the receiver functions to receive signals from django.
This commit is contained in:
parent
aaf829898b
commit
656bd3b530
@ -2,6 +2,8 @@ import collections
|
|||||||
import inspect
|
import inspect
|
||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
|
from importlib import import_module
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
@ -60,10 +62,14 @@ class PluginConfig(AppConfig):
|
|||||||
menu_items = 'navigation.menu_items'
|
menu_items = 'navigation.menu_items'
|
||||||
template_extensions = 'template_content.template_extensions'
|
template_extensions = 'template_content.template_extensions'
|
||||||
user_preferences = 'preferences.preferences'
|
user_preferences = 'preferences.preferences'
|
||||||
|
signals = 'signals'
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
plugin_name = self.name.rsplit('.', 1)[-1]
|
plugin_name = self.name.rsplit('.', 1)[-1]
|
||||||
|
|
||||||
|
# import signals module (if existing)
|
||||||
|
import_module(f"{self.__module__}.{self.signals}")
|
||||||
|
|
||||||
# Register template content (if defined)
|
# Register template content (if defined)
|
||||||
template_extensions = import_object(f"{self.__module__}.{self.template_extensions}")
|
template_extensions = import_object(f"{self.__module__}.{self.template_extensions}")
|
||||||
if template_extensions is not None:
|
if template_extensions is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user