|
@@ -14,9 +14,10 @@ from extras.plugins.utils import import_object
|
|
|
|
|
|
|
|
# Initialize plugin registry
|
|
# Initialize plugin registry
|
|
|
registry['plugins'] = {
|
|
registry['plugins'] = {
|
|
|
- 'template_extensions': collections.defaultdict(list),
|
|
|
|
|
|
|
+ 'graphql_schemas': [],
|
|
|
'menu_items': {},
|
|
'menu_items': {},
|
|
|
'preferences': {},
|
|
'preferences': {},
|
|
|
|
|
+ 'template_extensions': collections.defaultdict(list),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -55,13 +56,15 @@ class PluginConfig(AppConfig):
|
|
|
|
|
|
|
|
# Default integration paths. Plugin authors can override these to customize the paths to
|
|
# Default integration paths. Plugin authors can override these to customize the paths to
|
|
|
# integrated components.
|
|
# integrated components.
|
|
|
- template_extensions = 'template_content.template_extensions'
|
|
|
|
|
|
|
+ graphql_schema = 'graphql.schema'
|
|
|
menu_items = 'navigation.menu_items'
|
|
menu_items = 'navigation.menu_items'
|
|
|
|
|
+ template_extensions = 'template_content.template_extensions'
|
|
|
user_preferences = 'preferences.preferences'
|
|
user_preferences = 'preferences.preferences'
|
|
|
|
|
|
|
|
def ready(self):
|
|
def ready(self):
|
|
|
|
|
+ plugin_name = self.name.rsplit('.', 1)[1]
|
|
|
|
|
|
|
|
- # Register template content
|
|
|
|
|
|
|
+ # 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:
|
|
|
register_template_extensions(template_extensions)
|
|
register_template_extensions(template_extensions)
|
|
@@ -71,10 +74,14 @@ class PluginConfig(AppConfig):
|
|
|
if menu_items is not None:
|
|
if menu_items is not None:
|
|
|
register_menu_items(self.verbose_name, menu_items)
|
|
register_menu_items(self.verbose_name, menu_items)
|
|
|
|
|
|
|
|
- # Register user preferences
|
|
|
|
|
|
|
+ # Register GraphQL schema (if defined)
|
|
|
|
|
+ graphql_schema = import_object(f"{self.__module__}.{self.graphql_schema}")
|
|
|
|
|
+ if graphql_schema is not None:
|
|
|
|
|
+ register_graphql_schema(graphql_schema)
|
|
|
|
|
+
|
|
|
|
|
+ # Register user preferences (if defined)
|
|
|
user_preferences = import_object(f"{self.__module__}.{self.user_preferences}")
|
|
user_preferences = import_object(f"{self.__module__}.{self.user_preferences}")
|
|
|
if user_preferences is not None:
|
|
if user_preferences is not None:
|
|
|
- plugin_name = self.name.rsplit('.', 1)[1]
|
|
|
|
|
register_user_preferences(plugin_name, user_preferences)
|
|
register_user_preferences(plugin_name, user_preferences)
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
@@ -180,7 +187,7 @@ def register_template_extensions(class_list):
|
|
|
# Validation
|
|
# Validation
|
|
|
for template_extension in class_list:
|
|
for template_extension in class_list:
|
|
|
if not inspect.isclass(template_extension):
|
|
if not inspect.isclass(template_extension):
|
|
|
- raise TypeError(f"PluginTemplateExtension class {template_extension} was passes as an instance!")
|
|
|
|
|
|
|
+ raise TypeError(f"PluginTemplateExtension class {template_extension} was passed as an instance!")
|
|
|
if not issubclass(template_extension, PluginTemplateExtension):
|
|
if not issubclass(template_extension, PluginTemplateExtension):
|
|
|
raise TypeError(f"{template_extension} is not a subclass of extras.plugins.PluginTemplateExtension!")
|
|
raise TypeError(f"{template_extension} is not a subclass of extras.plugins.PluginTemplateExtension!")
|
|
|
if template_extension.model is None:
|
|
if template_extension.model is None:
|
|
@@ -254,6 +261,17 @@ def register_menu_items(section_name, class_list):
|
|
|
registry['plugins']['menu_items'][section_name] = class_list
|
|
registry['plugins']['menu_items'][section_name] = class_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+#
|
|
|
|
|
+# GraphQL schemas
|
|
|
|
|
+#
|
|
|
|
|
+
|
|
|
|
|
+def register_graphql_schema(graphql_schema):
|
|
|
|
|
+ """
|
|
|
|
|
+ Register a GraphQL schema class for inclusion in NetBox's GraphQL API.
|
|
|
|
|
+ """
|
|
|
|
|
+ registry['plugins']['graphql_schemas'].append(graphql_schema)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#
|
|
#
|
|
|
# User preferences
|
|
# User preferences
|
|
|
#
|
|
#
|