1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Clean up the application registry

This commit is contained in:
jeremystretch
2023-02-19 13:58:01 -05:00
parent c84f0de8f8
commit c109daf1d8
6 changed files with 53 additions and 65 deletions

View File

@@ -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()}"
)