From 8d326a841aa2a72217eba19abe2a230c02914526 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 13 Apr 2023 17:06:46 -0400 Subject: [PATCH] Replace custom simplify_decimal filter with floatformat --- netbox/dcim/tables/template_code.py | 4 ++-- netbox/templates/dcim/interface.html | 8 ++++---- .../wireless/inc/wirelesslink_interface.html | 4 ++-- netbox/utilities/templatetags/helpers.py | 14 -------------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index d390871c4..e0f38afef 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -12,12 +12,12 @@ LINKTERMINATION = """ CABLE_LENGTH = """ {% load helpers %} -{% if record.length %}{{ record.length|simplify_decimal }} {{ record.length_unit }}{% endif %} +{% if record.length %}{{ record.length|floatformat:"-2" }} {{ record.length_unit }}{% endif %} """ WEIGHT = """ {% load helpers %} -{% if value %}{{ value|simplify_decimal }} {{ record.weight_unit }}{% endif %} +{% if value %}{{ value|floatformat:"-2" }} {{ record.weight_unit }}{% endif %} """ DEVICE_LINK = """ diff --git a/netbox/templates/dcim/interface.html b/netbox/templates/dcim/interface.html index 1053f60f3..db0fd7dfd 100644 --- a/netbox/templates/dcim/interface.html +++ b/netbox/templates/dcim/interface.html @@ -242,7 +242,7 @@ Channel Frequency {% if object.rf_channel_frequency %} - {{ object.rf_channel_frequency|simplify_decimal }} MHz + {{ object.rf_channel_frequency|floatformat:"-2" }} MHz {% else %} {{ ''|placeholder }} {% endif %} @@ -250,7 +250,7 @@ {% if peer %} {% if peer.rf_channel_frequency %} - {{ peer.rf_channel_frequency|simplify_decimal }} MHz + {{ peer.rf_channel_frequency|floatformat:"-2" }} MHz {% else %} {{ ''|placeholder }} {% endif %} @@ -261,7 +261,7 @@ Channel Width {% if object.rf_channel_width %} - {{ object.rf_channel_width|simplify_decimal }} MHz + {{ object.rf_channel_width|floatformat:"-3" }} MHz {% else %} {{ ''|placeholder }} {% endif %} @@ -269,7 +269,7 @@ {% if peer %} {% if peer.rf_channel_width %} - {{ peer.rf_channel_width|simplify_decimal }} MHz + {{ peer.rf_channel_width|floatformat:"-3" }} MHz {% else %} {{ ''|placeholder }} {% endif %} diff --git a/netbox/templates/wireless/inc/wirelesslink_interface.html b/netbox/templates/wireless/inc/wirelesslink_interface.html index 7732816a7..b2ad55adf 100644 --- a/netbox/templates/wireless/inc/wirelesslink_interface.html +++ b/netbox/templates/wireless/inc/wirelesslink_interface.html @@ -31,7 +31,7 @@ Channel Frequency {% if interface.rf_channel_frequency %} - {{ interface.rf_channel_frequency|simplify_decimal }} MHz + {{ interface.rf_channel_frequency|floatformat:"-2" }} MHz {% else %} {{ ''|placeholder }} {% endif %} @@ -41,7 +41,7 @@ Channel Width {% if interface.rf_channel_width %} - {{ interface.rf_channel_width|simplify_decimal }} MHz + {{ interface.rf_channel_width|floatformat:"-3" }} MHz {% else %} {{ ''|placeholder }} {% endif %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 02534e659..f1489fd6d 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -30,7 +30,6 @@ __all__ = ( 'meters_to_feet', 'percentage', 'querystring', - 'simplify_decimal', 'startswith', 'status_from_tag', 'table_config_form', @@ -107,19 +106,6 @@ def humanize_megabytes(mb): return f'{mb} MB' -@register.filter() -def simplify_decimal(value): - """ - Return the simplest expression of a decimal value. Examples: - 1.00 => '1' - 1.20 => '1.2' - 1.23 => '1.23' - """ - if type(value) is not decimal.Decimal: - return value - return str(value).rstrip('0').rstrip('.') - - @register.filter(expects_localtime=True) def annotated_date(date_value): """