Finish layout for device view

This commit is contained in:
Jeremy Stretch
2025-11-06 12:31:20 -05:00
parent 60cc009d6b
commit e55a4ae603
4 changed files with 108 additions and 10 deletions

View File

@@ -89,6 +89,8 @@ class DevicePanel(panels.ObjectAttributesPanel):
class DeviceManagementPanel(panels.ObjectAttributesPanel):
title = _('Management')
status = attrs.ChoiceAttr('status')
role = attrs.NestedObjectAttr('role', linkify=True, max_depth=3)
platform = attrs.NestedObjectAttr('platform', linkify=True, max_depth=3)
@@ -111,6 +113,8 @@ class DeviceManagementPanel(panels.ObjectAttributesPanel):
class DeviceDimensionsPanel(panels.ObjectAttributesPanel):
title = _('Dimensions')
height = attrs.TextAttr('device_type.u_height', format_string='{}U')
total_weight = attrs.TemplatedAttr('total_weight', template_name='dcim/device/attrs/total_weight.html')
@@ -144,13 +148,32 @@ class VirtualChassisMembersPanel(panels.ObjectPanel):
title = _('Virtual Chassis Members')
def get_context(self, context):
"""
Return the context data to be used when rendering the panel.
Parameters:
context: The template context
"""
return {
**super().get_context(context),
'vc_members': context.get('vc_members'),
}
def render(self, context):
if not context.get('vc_members'):
return ''
return super().render(context)
class PowerUtilizationPanel(panels.ObjectPanel):
"""
A panel which displays the power utilization statistics for a device.
"""
template_name = 'dcim/panels/power_utilization.html'
title = _('Power Utilization')
def get_context(self, context):
return {
**super().get_context(context),
'vc_members': context.get('vc_members'),
}
def render(self, context):
obj = context['object']
if not obj.powerports.exists() or not obj.poweroutlets.exists():
return ''
return super().render(context)

View File

@@ -2456,7 +2456,7 @@ class DeviceView(generic.ObjectView):
],
right_panels=[
panels.DeviceManagementPanel(),
# TODO: Power utilization
panels.PowerUtilizationPanel(),
ObjectsTablePanel(
model='ipam.Service',
title=_('Application Services'),
@@ -2472,9 +2472,8 @@ class DeviceView(generic.ObjectView):
],
),
ImageAttachmentsPanel(),
panels.DeviceDimensionsPanel(title=_('Dimensions')),
# TODO: Rack elevations
# TemplatePanel('dcim/panels/rack_elevations.html'),
panels.DeviceDimensionsPanel(),
TemplatePanel('dcim/panels/device_rack_elevations.html'),
],
)