mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
parent
892fd95b5f
commit
e7ad6eeb74
@ -1,5 +1,5 @@
|
|||||||
import collections
|
import collections
|
||||||
from importlib.util import find_spec
|
from importlib import import_module
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -80,12 +80,15 @@ class PluginConfig(AppConfig):
|
|||||||
# Import from the configured path, if defined.
|
# Import from the configured path, if defined.
|
||||||
if getattr(self, name):
|
if getattr(self, name):
|
||||||
return import_string(f"{self.__module__}.{self.name}")
|
return import_string(f"{self.__module__}.{self.name}")
|
||||||
|
|
||||||
# Fall back to the resource's default path. Return None if the module has not been provided.
|
# Fall back to the resource's default path. Return None if the module has not been provided.
|
||||||
default_path = DEFAULT_RESOURCE_PATHS[name]
|
default_path = f'{self.__module__}.{DEFAULT_RESOURCE_PATHS[name]}'
|
||||||
default_module = f'{self.__module__}.{default_path}'.rsplit('.', 1)[0]
|
default_module, resource_name = default_path.rsplit('.', 1)
|
||||||
if find_spec(default_module):
|
try:
|
||||||
setattr(self, name, default_path)
|
module = import_module(default_module)
|
||||||
return import_string(f"{self.__module__}.{default_path}")
|
return getattr(module, resource_name, None)
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
plugin_name = self.name.rsplit('.', 1)[-1]
|
plugin_name = self.name.rsplit('.', 1)[-1]
|
||||||
|
Loading…
Reference in New Issue
Block a user