mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-09 19:03:48 +02:00
Replace all instantiations of Panel with TemplatePanel
This commit is contained in:
@@ -27,7 +27,6 @@ from netbox.ui.panels import (
|
|||||||
NestedGroupObjectPanel,
|
NestedGroupObjectPanel,
|
||||||
ObjectsTablePanel,
|
ObjectsTablePanel,
|
||||||
OrganizationalObjectPanel,
|
OrganizationalObjectPanel,
|
||||||
Panel,
|
|
||||||
RelatedObjectsPanel,
|
RelatedObjectsPanel,
|
||||||
TemplatePanel,
|
TemplatePanel,
|
||||||
)
|
)
|
||||||
@@ -1764,7 +1763,7 @@ class ModuleTypeView(GetRelatedModelsMixin, generic.ObjectView):
|
|||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Attributes'),
|
title=_('Attributes'),
|
||||||
template_name='dcim/panels/module_type_attributes.html',
|
template_name='dcim/panels/module_type_attributes.html',
|
||||||
),
|
),
|
||||||
@@ -2934,7 +2933,7 @@ class ModuleView(GetRelatedModelsMixin, generic.ObjectView):
|
|||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Module Type'),
|
title=_('Module Type'),
|
||||||
template_name='dcim/panels/module_type.html',
|
template_name='dcim/panels/module_type.html',
|
||||||
),
|
),
|
||||||
@@ -3740,7 +3739,7 @@ class ModuleBayView(generic.ObjectView):
|
|||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
CustomFieldsPanel(),
|
CustomFieldsPanel(),
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Installed Module'),
|
title=_('Installed Module'),
|
||||||
template_name='dcim/panels/installed_module.html',
|
template_name='dcim/panels/installed_module.html',
|
||||||
),
|
),
|
||||||
@@ -3815,7 +3814,7 @@ class DeviceBayView(generic.ObjectView):
|
|||||||
TagsPanel(),
|
TagsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Installed Device'),
|
title=_('Installed Device'),
|
||||||
template_name='dcim/panels/installed_device.html',
|
template_name='dcim/panels/installed_device.html',
|
||||||
),
|
),
|
||||||
@@ -4310,11 +4309,11 @@ class CableView(generic.ObjectView):
|
|||||||
CommentsPanel(),
|
CommentsPanel(),
|
||||||
],
|
],
|
||||||
right_panels=[
|
right_panels=[
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Termination A'),
|
title=_('Termination A'),
|
||||||
template_name='dcim/panels/cable_termination_a.html',
|
template_name='dcim/panels/cable_termination_a.html',
|
||||||
),
|
),
|
||||||
Panel(
|
TemplatePanel(
|
||||||
title=_('Termination B'),
|
title=_('Termination B'),
|
||||||
template_name='dcim/panels/cable_termination_b.html',
|
template_name='dcim/panels/cable_termination_b.html',
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -45,18 +45,15 @@ class Panel:
|
|||||||
Parameters:
|
Parameters:
|
||||||
title (str): The human-friendly title of the panel
|
title (str): The human-friendly title of the panel
|
||||||
actions (list): An iterable of PanelActions to include in the panel header
|
actions (list): An iterable of PanelActions to include in the panel header
|
||||||
template_name (str): Overrides the default template name, if defined
|
|
||||||
"""
|
"""
|
||||||
template_name = None
|
template_name = None
|
||||||
title = None
|
title = None
|
||||||
actions = None
|
actions = None
|
||||||
|
|
||||||
def __init__(self, title=None, actions=None, template_name=None):
|
def __init__(self, title=None, actions=None):
|
||||||
if title is not None:
|
if title is not None:
|
||||||
self.title = title
|
self.title = title
|
||||||
self.actions = actions or self.actions or []
|
self.actions = actions or self.actions or []
|
||||||
if template_name is not None:
|
|
||||||
self.template_name = template_name
|
|
||||||
|
|
||||||
def get_context(self, context):
|
def get_context(self, context):
|
||||||
"""
|
"""
|
||||||
@@ -324,12 +321,17 @@ class TemplatePanel(Panel):
|
|||||||
Parameters:
|
Parameters:
|
||||||
template_name (str): The name of the template to render
|
template_name (str): The name of the template to render
|
||||||
"""
|
"""
|
||||||
def __init__(self, template_name):
|
def __init__(self, template_name, **kwargs):
|
||||||
super().__init__(template_name=template_name)
|
self.template_name = template_name
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
# Pass the entire context to the template
|
# Pass the entire context to the template, but let the panel's own context take precedence
|
||||||
return render_to_string(self.template_name, context.flatten())
|
# for panel-specific variables (title, actions, panel_class)
|
||||||
|
return render_to_string(self.template_name, {
|
||||||
|
**context.flatten(),
|
||||||
|
**self.get_context(context),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class TextCodePanel(ObjectPanel):
|
class TextCodePanel(ObjectPanel):
|
||||||
|
|||||||
Reference in New Issue
Block a user