fix hard code html

This commit is contained in:
tranthang2404 2022-03-14 23:36:29 +07:00
parent bf83e223ab
commit e5b23e5219
3 changed files with 6 additions and 9 deletions

View File

@ -250,7 +250,7 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
child_prefixes = netaddr.IPSet([p.prefix for p in queryset]) child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
utilization = float(child_prefixes.size) / self.prefix.size * 100 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') @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
@ -560,7 +560,7 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
prefix_size -= 2 prefix_size -= 2
utilization = float(child_ips.size) / prefix_size * 100 utilization = float(child_ips.size) / prefix_size * 100
return utilization return min(utilization, 100)
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')

View File

@ -9,13 +9,8 @@
aria-valuemin="0" aria-valuemin="0"
aria-valuemax="100" aria-valuemax="100"
aria-valuenow="{{ utilization }}" aria-valuenow="{{ utilization }}"
{% if utilization == 100 %}
class="progress-bar"
style="width: {{ utilization }}%; background-color: #800080;"
{% else %}
class="progress-bar {{ bar_class }}" class="progress-bar {{ bar_class }}"
style="width: {{ utilization }}%;" style="width: {{ utilization }}%;"
{% endif %}
> >
{% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %} {% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %}
</div> </div>

View File

@ -389,7 +389,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
""" """
Display a horizontal bar graph indicating a percentage of utilization. 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' bar_class = 'bg-danger'
elif warning_threshold and utilization >= warning_threshold: elif warning_threshold and utilization >= warning_threshold:
bar_class = 'bg-warning' bar_class = 'bg-warning'