mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-24 01:38:47 +02:00
Closes #21890: Deprecate the 'models' registry key
This commit is contained in:
@@ -722,10 +722,10 @@ def register_models(*models):
|
|||||||
for model in models:
|
for model in models:
|
||||||
app_label, model_name = model._meta.label_lower.split('.')
|
app_label, model_name = model._meta.label_lower.split('.')
|
||||||
|
|
||||||
# TODO: Remove in NetBox v4.5
|
# TODO: Remove in NetBox v4.7
|
||||||
# Register public models
|
# Register public models (access the underlying dict directly to avoid triggering the deprecation warning)
|
||||||
if not getattr(model, '_netbox_private', False):
|
if not getattr(model, '_netbox_private', False):
|
||||||
registry['models'][app_label].add(model_name)
|
dict.__getitem__(registry, 'models')[app_label].add(model_name)
|
||||||
|
|
||||||
# Register applicable feature views for the model
|
# Register applicable feature views for the model
|
||||||
if issubclass(model, ContactsMixin):
|
if issubclass(model, ContactsMixin):
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ class Registry(dict):
|
|||||||
removed (though the value of each key is mutable).
|
removed (though the value of each key is mutable).
|
||||||
"""
|
"""
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
# TODO: Remove in NetBox v4.7
|
||||||
|
if key == 'models':
|
||||||
|
import warnings
|
||||||
|
warnings.warn(
|
||||||
|
'The "models" registry key is deprecated and will be removed in NetBox v4.7. Registered models can be '
|
||||||
|
'obtained by calling ObjectType.objects.public().',
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
return super().__getitem__(key)
|
return super().__getitem__(key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -29,6 +38,7 @@ registry = Registry({
|
|||||||
'event_types': dict(),
|
'event_types': dict(),
|
||||||
'filtersets': dict(),
|
'filtersets': dict(),
|
||||||
'model_features': dict(),
|
'model_features': dict(),
|
||||||
|
# TODO: Remove in NetBox v4.7
|
||||||
'models': collections.defaultdict(set),
|
'models': collections.defaultdict(set),
|
||||||
'plugins': dict(),
|
'plugins': dict(),
|
||||||
'request_processors': list(),
|
'request_processors': list(),
|
||||||
|
|||||||
Reference in New Issue
Block a user