From e5b23e521905bac1ba576ef94faa92a90bb9807c Mon Sep 17 00:00:00 2001 From: tranthang2404 Date: Mon, 14 Mar 2022 23:36:29 +0700 Subject: [PATCH] fix hard code html --- netbox/ipam/models/ip.py | 4 ++-- netbox/utilities/templates/helpers/utilization_graph.html | 7 +------ netbox/utilities/templatetags/helpers.py | 4 +++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 8369b3c58..7d9937c1b 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -250,7 +250,7 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel): child_prefixes = netaddr.IPSet([p.prefix for p in queryset]) utilization = float(child_prefixes.size) / self.prefix.size * 100 - return utilization + return min(utilization, 100) @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') @@ -560,7 +560,7 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel): prefix_size -= 2 utilization = float(child_ips.size) / prefix_size * 100 - return utilization + return min(utilization, 100) @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') diff --git a/netbox/utilities/templates/helpers/utilization_graph.html b/netbox/utilities/templates/helpers/utilization_graph.html index 1d6bc44d6..a93ccf565 100644 --- a/netbox/utilities/templates/helpers/utilization_graph.html +++ b/netbox/utilities/templates/helpers/utilization_graph.html @@ -9,15 +9,10 @@ aria-valuemin="0" aria-valuemax="100" aria-valuenow="{{ utilization }}" - {% if utilization == 100 %} - class="progress-bar" - style="width: {{ utilization }}%; background-color: #800080;" - {% else %} class="progress-bar {{ bar_class }}" style="width: {{ utilization }}%;" - {% endif %} > - {% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %} + {% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %} {% if utilization < 25 %} {{ utilization|floatformat:-2 }}% diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 0e45cb581..cff3428c0 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -389,7 +389,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90): """ Display a horizontal bar graph indicating a percentage of utilization. """ - if danger_threshold and utilization >= danger_threshold: + if utilization == 100: + bar_class = 'bg-secondary' + elif danger_threshold and utilization >= danger_threshold: bar_class = 'bg-danger' elif warning_threshold and utilization >= warning_threshold: bar_class = 'bg-warning'