mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Refactor plugins registry
This commit is contained in:
@@ -12,10 +12,12 @@ from utilities.choices import ButtonColorChoices
|
||||
from extras.plugins.utils import import_object
|
||||
|
||||
|
||||
# Initialize plugin registry stores
|
||||
registry['plugin_template_extensions'] = collections.defaultdict(list)
|
||||
registry['plugin_menu_items'] = {}
|
||||
registry['plugin_preferences'] = {}
|
||||
# Initialize plugin registry
|
||||
registry['plugins'] = {
|
||||
'template_extensions': collections.defaultdict(list),
|
||||
'menu_items': {},
|
||||
'preferences': {},
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
@@ -184,7 +186,7 @@ def register_template_extensions(class_list):
|
||||
if template_extension.model is None:
|
||||
raise TypeError(f"PluginTemplateExtension class {template_extension} does not define a valid model!")
|
||||
|
||||
registry['plugin_template_extensions'][template_extension.model].append(template_extension)
|
||||
registry['plugins']['template_extensions'][template_extension.model].append(template_extension)
|
||||
|
||||
|
||||
#
|
||||
@@ -249,7 +251,7 @@ def register_menu_items(section_name, class_list):
|
||||
if not isinstance(button, PluginMenuButton):
|
||||
raise TypeError(f"{button} must be an instance of extras.plugins.PluginMenuButton")
|
||||
|
||||
registry['plugin_menu_items'][section_name] = class_list
|
||||
registry['plugins']['menu_items'][section_name] = class_list
|
||||
|
||||
|
||||
#
|
||||
@@ -260,4 +262,4 @@ def register_user_preferences(plugin_name, preferences):
|
||||
"""
|
||||
Register a list of user preferences defined by a plugin.
|
||||
"""
|
||||
registry['plugin_preferences'][plugin_name] = preferences
|
||||
registry['plugins']['preferences'][plugin_name] = preferences
|
||||
|
Reference in New Issue
Block a user