From f769f773f1bbfdcebc2d15e79f233ba3e6a829c1 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 23 Sep 2024 14:31:06 -0400 Subject: [PATCH 1/2] Respect the weight unit of the DeviceType when displaying the Device details --- netbox/templates/dcim/device.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index b74d4b5f667..867c70c8b1a 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -324,7 +324,11 @@

{% trans "Dimensions" %}

{% trans "Weight" %} {% if object.total_weight %} - {{ object.total_weight|floatformat }} {% trans "Kilograms" %} + {% if object.device_type.weight_unit == "lb" %} + {{ object.total_weight|kg_to_pounds|floatformat }} {% trans "Pounds" %} + {% elif object.device_type.weight_unit == "kg" %} + {{ object.total_weight|floatformat }} {% trans "Kilograms" %} + {% endif %} {% else %} {{ ''|placeholder }} {% endif %} From 0c90284448247623101a580d207d58d66fa1d5ec Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 23 Sep 2024 17:45:10 -0400 Subject: [PATCH 2/2] Reuse the same weight formatting construct as in rack.html, and add placeholder in rack if empty --- netbox/templates/dcim/device.html | 7 ++----- netbox/templates/dcim/rack.html | 8 ++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 867c70c8b1a..fb11e9a5c7d 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -324,11 +324,8 @@

{% trans "Dimensions" %}

{% trans "Weight" %} {% if object.total_weight %} - {% if object.device_type.weight_unit == "lb" %} - {{ object.total_weight|kg_to_pounds|floatformat }} {% trans "Pounds" %} - {% elif object.device_type.weight_unit == "kg" %} - {{ object.total_weight|floatformat }} {% trans "Kilograms" %} - {% endif %} + {{ object.total_weight|floatformat }} {% trans "Kilograms" %} + ({{ object.total_weight|kg_to_pounds|floatformat }} {% trans "Pounds" %}) {% else %} {{ ''|placeholder }} {% endif %} diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index ad035dd6bac..eec4d63a583 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -103,8 +103,12 @@

{% trans "Weight" %}

{% trans "Total Weight" %} - {{ object.total_weight|floatformat }} {% trans "Kilograms" %} - ({{ object.total_weight|kg_to_pounds|floatformat }} {% trans "Pounds" %}) + {% if object.total_weight %} + {{ object.total_weight|floatformat }} {% trans "Kilograms" %} + ({{ object.total_weight|kg_to_pounds|floatformat }} {% trans "Pounds" %}) + {% else %} + {{ ''|placeholder }} + {% endif %}