Skip to content

Commit

Permalink
Closes #18072: Remove support for single model registration from Plug…
Browse files Browse the repository at this point in the history
…inTemplateExtension
  • Loading branch information
jeremystretch committed Feb 20, 2025
1 parent ef89fc1 commit 5cd1f56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 2 additions & 10 deletions netbox/netbox/plugins/registration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import warnings

from django.utils.translation import gettext_lazy as _

from netbox.registry import registry
from .navigation import PluginMenu, PluginMenuButton, PluginMenuItem
from .templates import PluginTemplateExtension
Expand Down Expand Up @@ -35,16 +35,8 @@ def register_template_extensions(class_list):
)

if template_extension.models:
# Registration for multiple models
# Registration for specific models
models = template_extension.models
elif template_extension.model:
# Registration for a single model (deprecated)
warnings.warn(
"PluginTemplateExtension.model is deprecated and will be removed in a future release. Use "
"'models' instead.",
DeprecationWarning
)
models = [template_extension.model]
else:
# Global registration (no specific models)
models = [None]
Expand Down
11 changes: 8 additions & 3 deletions netbox/netbox/plugins/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ class PluginTemplateExtension:
This class is used to register plugin content to be injected into core NetBox templates. It contains methods
that are overridden by plugin authors to return template content.
The `model` attribute on the class defines the which model detail page this class renders content for. It
should be set as a string in the form '<app_label>.<model_name>'. render() provides the following context data:
The `models` attribute on the class defines the which specific model detail pages this class renders content
for. It should be defined as a list of strings in the following form:
models = ['<app_label>.<model_name>', '<app_label>.<model_name>']
If `models` is left as None, the extension will render for _all_ models.
The `render()` method provides the following context data:
* object - The object being viewed (object views only)
* model - The type of object being viewed (list views only)
Expand All @@ -21,7 +27,6 @@ class PluginTemplateExtension:
* config - Plugin-specific configuration parameters
"""
models = None
model = None # Deprecated; use `models` instead

def __init__(self, context):
self.context = context
Expand Down

0 comments on commit 5cd1f56

Please sign in to comment.