From 5fc40c74e25e4aa4dce6d484ba17e8c1b4bea5ee Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 20 Mar 2025 13:20:10 -0700 Subject: [PATCH] 16224 update table display --- netbox/dcim/tables/racks.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/netbox/dcim/tables/racks.py b/netbox/dcim/tables/racks.py index 610dc1a32..ee0df9891 100644 --- a/netbox/dcim/tables/racks.py +++ b/netbox/dcim/tables/racks.py @@ -1,6 +1,7 @@ from django.utils.translation import gettext_lazy as _ import django_tables2 as tables from django_tables2.utils import Accessor +from django.utils.safestring import mark_safe from dcim.models import Rack, RackReservation, RackRole, RackType from netbox.tables import NetBoxTable, columns @@ -15,6 +16,19 @@ __all__ = ( ) +class OuterUnitColumn(tables.Column): + """ + Render a model's outer unit value with unit designation or placeholder if the value is None. + """ + DEFAULT_BG_COLOR = 'secondary' + + def render(self, record, value): + if value is None: + return mark_safe('') + + return mark_safe(f'{value} {record.outer_unit}') + + # # Rack roles # @@ -62,16 +76,13 @@ class RackTypeTable(NetBoxTable): template_code="{{ value }}U", verbose_name=_('Height') ) - outer_width = tables.TemplateColumn( - template_code="{{ record.outer_width }} {{ record.outer_unit }}", + outer_width = OuterUnitColumn( verbose_name=_('Outer Width') ) - outer_height = tables.TemplateColumn( - template_code="{{ record.outer_height }} {{ record.outer_unit }}", + outer_height = OuterUnitColumn( verbose_name=_('Outer Height') ) - outer_depth = tables.TemplateColumn( - template_code="{{ record.outer_depth }} {{ record.outer_unit }}", + outer_depth = OuterUnitColumn( verbose_name=_('Outer Depth') ) weight = columns.TemplateColumn( @@ -163,16 +174,13 @@ class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable): tags = columns.TagColumn( url_name='dcim:rack_list' ) - outer_width = tables.TemplateColumn( - template_code="{{ record.outer_width }} {{ record.outer_unit }}", + outer_width = OuterUnitColumn( verbose_name=_('Outer Width') ) - outer_height = tables.TemplateColumn( - template_code="{{ record.outer_height }} {{ record.outer_unit }}", + outer_height = OuterUnitColumn( verbose_name=_('Outer Height') ) - outer_depth = tables.TemplateColumn( - template_code="{{ record.outer_depth }} {{ record.outer_unit }}", + outer_depth = OuterUnitColumn( verbose_name=_('Outer Depth') ) weight = columns.TemplateColumn(