mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -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 _
|
from django.utils.translation import gettext_lazy as _
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from dcim.models import Rack, RackReservation, RackRole, RackType
|
from dcim.models import Rack, RackReservation, RackRole, RackType
|
||||||
from netbox.tables import NetBoxTable, columns
|
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
|
# Rack roles
|
||||||
#
|
#
|
||||||
@ -62,16 +76,13 @@ class RackTypeTable(NetBoxTable):
|
|||||||
template_code="{{ value }}U",
|
template_code="{{ value }}U",
|
||||||
verbose_name=_('Height')
|
verbose_name=_('Height')
|
||||||
)
|
)
|
||||||
outer_width = tables.TemplateColumn(
|
outer_width = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_width }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Width')
|
verbose_name=_('Outer Width')
|
||||||
)
|
)
|
||||||
outer_height = tables.TemplateColumn(
|
outer_height = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_height }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Height')
|
verbose_name=_('Outer Height')
|
||||||
)
|
)
|
||||||
outer_depth = tables.TemplateColumn(
|
outer_depth = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_depth }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Depth')
|
verbose_name=_('Outer Depth')
|
||||||
)
|
)
|
||||||
weight = columns.TemplateColumn(
|
weight = columns.TemplateColumn(
|
||||||
@ -163,16 +174,13 @@ class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
|||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='dcim:rack_list'
|
url_name='dcim:rack_list'
|
||||||
)
|
)
|
||||||
outer_width = tables.TemplateColumn(
|
outer_width = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_width }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Width')
|
verbose_name=_('Outer Width')
|
||||||
)
|
)
|
||||||
outer_height = tables.TemplateColumn(
|
outer_height = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_height }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Height')
|
verbose_name=_('Outer Height')
|
||||||
)
|
)
|
||||||
outer_depth = tables.TemplateColumn(
|
outer_depth = OuterUnitColumn(
|
||||||
template_code="{{ record.outer_depth }} {{ record.outer_unit }}",
|
|
||||||
verbose_name=_('Outer Depth')
|
verbose_name=_('Outer Depth')
|
||||||
)
|
)
|
||||||
weight = columns.TemplateColumn(
|
weight = columns.TemplateColumn(
|
||||||
|
Loading…
Reference in New Issue
Block a user