mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
16224 update table display
This commit is contained in:
parent
c72a14e6a6
commit
5fc40c74e2
@ -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('<span class="text-muted">—</span>')
|
||||
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user