Panel.render() should pass the request to render_to_string()

This commit is contained in:
Jeremy Stretch
2026-04-02 10:28:35 -04:00
parent 1ccab930ef
commit cb983c6308
3 changed files with 7 additions and 20 deletions

View File

@@ -1,5 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, attrs, panels
@@ -393,10 +392,6 @@ class ConnectionPanel(panels.ObjectPanel):
'show_endpoints': self.show_endpoints,
}
def render(self, context):
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
class InventoryItemsPanel(panels.ObjectPanel):
"""
@@ -414,10 +409,6 @@ class InventoryItemsPanel(panels.ObjectPanel):
),
]
def render(self, context):
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
class VirtualChassisMembersPanel(panels.ObjectPanel):
"""
@@ -531,8 +522,7 @@ class InterfaceConnectionPanel(panels.ObjectPanel):
obj = context.get('object')
if obj and obj.is_virtual:
return ''
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
return super().render(context)
class VirtualCircuitPanel(panels.ObjectPanel):
@@ -546,8 +536,7 @@ class VirtualCircuitPanel(panels.ObjectPanel):
obj = context.get('object')
if not obj or not obj.is_virtual or not hasattr(obj, 'virtual_circuit_termination'):
return ''
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
return super().render(context)
class InterfaceWirelessPanel(panels.ObjectPanel):
@@ -561,8 +550,7 @@ class InterfaceWirelessPanel(panels.ObjectPanel):
obj = context.get('object')
if not obj or not obj.is_wireless:
return ''
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
return super().render(context)
class WirelessLANsPanel(panels.ObjectPanel):
@@ -576,5 +564,4 @@ class WirelessLANsPanel(panels.ObjectPanel):
obj = context.get('object')
if not obj or not obj.is_wireless:
return ''
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
return super().render(context)

View File

@@ -1,5 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, attrs, panels
@@ -70,7 +69,7 @@ class CustomFieldsPanel(panels.ObjectPanel):
# Hide the panel if no custom fields exist
if not ctx['custom_fields']:
return ''
return render_to_string(self.template_name, self.get_context(context))
return super().render(context)
class ImageAttachmentsPanel(panels.ObjectsTablePanel):

View File

@@ -78,7 +78,8 @@ class Panel:
Parameters:
context (dict): The template context
"""
return render_to_string(self.template_name, self.get_context(context))
ctx = self.get_context(context)
return render_to_string(self.template_name, ctx, request=ctx.get('request'))
#