mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-12 04:00:02 +02:00
Compare commits
1 Commits
feature
...
21890-depr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
903c478454 |
@@ -51,6 +51,7 @@ class ObjectTypeManager(models.Manager):
|
||||
"""
|
||||
return self.get(app_label=app_label, model=model)
|
||||
|
||||
# TODO: Remove in NetBox v4.5
|
||||
def get_for_id(self, id):
|
||||
"""
|
||||
Retrieve an ObjectType by its primary key (numeric ID).
|
||||
|
||||
@@ -44,9 +44,9 @@ ADVISORY_LOCK_KEYS = {
|
||||
'job-schedules': 110100,
|
||||
}
|
||||
|
||||
# TODO: Remove in NetBox v4.7
|
||||
# TODO: Remove in NetBox v4.5
|
||||
# Legacy default view action permission mapping
|
||||
_DEFAULT_ACTION_PERMISSIONS = {
|
||||
DEFAULT_ACTION_PERMISSIONS = {
|
||||
'add': {'add'},
|
||||
'export': {'view'},
|
||||
'bulk_import': {'add'},
|
||||
@@ -54,20 +54,6 @@ _DEFAULT_ACTION_PERMISSIONS = {
|
||||
'bulk_delete': {'delete'},
|
||||
}
|
||||
|
||||
|
||||
def __getattr__(name):
|
||||
if name == 'DEFAULT_ACTION_PERMISSIONS':
|
||||
import warnings
|
||||
warnings.warn(
|
||||
f"{name} is deprecated and will be removed in NetBox v4.7. "
|
||||
"Define action permissions via ObjectAction subclasses instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return _DEFAULT_ACTION_PERMISSIONS
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
|
||||
# General-purpose tokens
|
||||
CENSOR_TOKEN = '********'
|
||||
CENSOR_TOKEN_CHANGED = '***CHANGED***'
|
||||
|
||||
@@ -722,10 +722,10 @@ def register_models(*models):
|
||||
for model in models:
|
||||
app_label, model_name = model._meta.label_lower.split('.')
|
||||
|
||||
# TODO: Remove in NetBox v4.5
|
||||
# Register public models
|
||||
# TODO: Remove in NetBox v4.7
|
||||
# Register public models (access the underlying dict directly to avoid triggering the deprecation warning)
|
||||
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
|
||||
if issubclass(model, ContactsMixin):
|
||||
|
||||
@@ -9,6 +9,15 @@ class Registry(dict):
|
||||
removed (though the value of each key is mutable).
|
||||
"""
|
||||
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:
|
||||
return super().__getitem__(key)
|
||||
except KeyError:
|
||||
@@ -29,6 +38,7 @@ registry = Registry({
|
||||
'event_types': dict(),
|
||||
'filtersets': dict(),
|
||||
'model_features': dict(),
|
||||
# TODO: Remove in NetBox v4.7
|
||||
'models': collections.defaultdict(set),
|
||||
'plugins': dict(),
|
||||
'request_processors': list(),
|
||||
|
||||
@@ -9,7 +9,7 @@ __all__ = (
|
||||
'TableMixin',
|
||||
)
|
||||
|
||||
# TODO: Remove in NetBox v4.7
|
||||
# TODO: Remove in NetBox v4.5
|
||||
LEGACY_ACTIONS = {
|
||||
'add': object_actions.AddObject,
|
||||
'edit': object_actions.EditObject,
|
||||
@@ -33,7 +33,7 @@ class ActionsMixin:
|
||||
"""
|
||||
actions = tuple()
|
||||
|
||||
# TODO: Remove in NetBox v4.7
|
||||
# TODO: Remove in NetBox v4.5
|
||||
def _convert_legacy_actions(self):
|
||||
"""
|
||||
Convert a legacy dictionary mapping action name to required permissions to a list of ObjectAction subclasses.
|
||||
@@ -41,14 +41,6 @@ class ActionsMixin:
|
||||
if type(self.actions) is not dict:
|
||||
return
|
||||
|
||||
import warnings
|
||||
warnings.warn(
|
||||
f"{self.__class__.__name__}.actions is defined as a dictionary, which is deprecated and will be removed "
|
||||
"in NetBox v4.7. Define actions as a list of ObjectAction subclasses instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
actions = []
|
||||
for name in self.actions.keys():
|
||||
try:
|
||||
@@ -64,7 +56,7 @@ class ActionsMixin:
|
||||
"""
|
||||
model = model or self.queryset.model
|
||||
|
||||
# TODO: Remove in NetBox v4.7
|
||||
# TODO: Remove in NetBox v4.5
|
||||
# Handle legacy action sets
|
||||
self._convert_legacy_actions()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user