mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-06 07:16:25 -06:00
Clean up the application registry
This commit is contained in:
@@ -1,14 +1,2 @@
|
||||
# Webhook content types
|
||||
HTTP_CONTENT_TYPE_JSON = 'application/json'
|
||||
|
||||
# Registerable extras features
|
||||
EXTRAS_FEATURES = [
|
||||
'custom_fields',
|
||||
'custom_links',
|
||||
'export_templates',
|
||||
'job_results',
|
||||
'journaling',
|
||||
'synced_data',
|
||||
'tags',
|
||||
'webhooks'
|
||||
]
|
||||
|
||||
@@ -14,13 +14,13 @@ from .registration import *
|
||||
from .templates import *
|
||||
|
||||
# Initialize plugin registry
|
||||
registry['plugins'] = {
|
||||
registry['plugins'].update({
|
||||
'graphql_schemas': [],
|
||||
'menus': [],
|
||||
'menu_items': {},
|
||||
'preferences': {},
|
||||
'template_extensions': collections.defaultdict(list),
|
||||
}
|
||||
})
|
||||
|
||||
DEFAULT_RESOURCE_PATHS = {
|
||||
'search_indexes': 'search.indexes',
|
||||
|
||||
+11
-6
@@ -2,7 +2,6 @@ from django.db.models import Q
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from taggit.managers import _TaggableManager
|
||||
|
||||
from extras.constants import EXTRAS_FEATURES
|
||||
from netbox.registry import registry
|
||||
|
||||
|
||||
@@ -18,7 +17,7 @@ def is_taggable(obj):
|
||||
|
||||
def image_upload(instance, filename):
|
||||
"""
|
||||
Return a path for uploading image attchments.
|
||||
Return a path for uploading image attachments.
|
||||
"""
|
||||
path = 'image-attachments/'
|
||||
|
||||
@@ -56,8 +55,14 @@ class FeatureQuery:
|
||||
|
||||
|
||||
def register_features(model, features):
|
||||
"""
|
||||
Register model features in the application registry.
|
||||
"""
|
||||
app_label, model_name = model._meta.label_lower.split('.')
|
||||
for feature in features:
|
||||
if feature not in EXTRAS_FEATURES:
|
||||
raise ValueError(f"{feature} is not a valid extras feature!")
|
||||
app_label, model_name = model._meta.label_lower.split('.')
|
||||
registry['model_features'][feature][app_label].add(model_name)
|
||||
try:
|
||||
registry['model_features'][feature][app_label].add(model_name)
|
||||
except KeyError:
|
||||
raise KeyError(
|
||||
f"{feature} is not a valid model feature! Valid keys are: {registry['model_features'].keys()}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user