mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-03 22:06:26 -06:00
fix(dcim): Render device height as rack units via floatformat
Use `TemplatedAttr` for device height and render using Django's `floatformat` filter so 0.0 is displayed as `0U` (and whole-U values omit the decimal). Fixes #21267
This commit is contained in:
@@ -125,7 +125,7 @@ class DeviceManagementPanel(panels.ObjectAttributesPanel):
|
|||||||
class DeviceDimensionsPanel(panels.ObjectAttributesPanel):
|
class DeviceDimensionsPanel(panels.ObjectAttributesPanel):
|
||||||
title = _('Dimensions')
|
title = _('Dimensions')
|
||||||
|
|
||||||
height = attrs.TextAttr('device_type.u_height', format_string='{}U')
|
height = attrs.TemplatedAttr('device_type.u_height', template_name='dcim/devicetype/attrs/height.html')
|
||||||
total_weight = attrs.TemplatedAttr('total_weight', template_name='dcim/device/attrs/total_weight.html')
|
total_weight = attrs.TemplatedAttr('total_weight', template_name='dcim/device/attrs/total_weight.html')
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class DeviceTypePanel(panels.ObjectAttributesPanel):
|
|||||||
part_number = attrs.TextAttr('part_number')
|
part_number = attrs.TextAttr('part_number')
|
||||||
default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True)
|
default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True)
|
||||||
description = attrs.TextAttr('description')
|
description = attrs.TextAttr('description')
|
||||||
height = attrs.TextAttr('u_height', format_string='{}U', label=_('Height'))
|
height = attrs.TemplatedAttr('u_height', template_name='dcim/devicetype/attrs/height.html')
|
||||||
exclude_from_utilization = attrs.BooleanAttr('exclude_from_utilization')
|
exclude_from_utilization = attrs.BooleanAttr('exclude_from_utilization')
|
||||||
full_depth = attrs.BooleanAttr('is_full_depth')
|
full_depth = attrs.BooleanAttr('is_full_depth')
|
||||||
weight = attrs.NumericAttr('weight', unit_accessor='get_weight_unit_display')
|
weight = attrs.NumericAttr('weight', unit_accessor='get_weight_unit_display')
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class TextAttr(ObjectAttribute):
|
|||||||
def get_value(self, obj):
|
def get_value(self, obj):
|
||||||
value = resolve_attr_path(obj, self.accessor)
|
value = resolve_attr_path(obj, self.accessor)
|
||||||
# Apply format string (if any)
|
# Apply format string (if any)
|
||||||
if value and self.format_string:
|
if value is not None and value != '' and self.format_string:
|
||||||
return self.format_string.format(value)
|
return self.format_string.format(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{{ value|floatformat }}U
|
||||||
Reference in New Issue
Block a user