mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
Replace custom simplify_decimal filter with floatformat
This commit is contained in:
parent
134dc70a4d
commit
8d326a841a
@ -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 = """
|
||||
|
@ -242,7 +242,7 @@
|
||||
<th scope="row">Channel Frequency</th>
|
||||
<td>
|
||||
{% 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 %}
|
||||
<td{% if peer.rf_channel_frequency != object.rf_channel_frequency %} class="text-danger"{% endif %}>
|
||||
{% 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 @@
|
||||
<th scope="row">Channel Width</th>
|
||||
<td>
|
||||
{% 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 %}
|
||||
<td{% if peer.rf_channel_width != object.rf_channel_width %} class="text-danger"{% endif %}>
|
||||
{% if peer.rf_channel_width %}
|
||||
{{ peer.rf_channel_width|simplify_decimal }} MHz
|
||||
{{ peer.rf_channel_width|floatformat:"-3" }} MHz
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
@ -31,7 +31,7 @@
|
||||
<th scope="row">Channel Frequency</th>
|
||||
<td>
|
||||
{% 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 @@
|
||||
<th scope="row">Channel Width</th>
|
||||
<td>
|
||||
{% if interface.rf_channel_width %}
|
||||
{{ interface.rf_channel_width|simplify_decimal }} MHz
|
||||
{{ interface.rf_channel_width|floatformat:"-3" }} MHz
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user