1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Created a template tag for displaying utilization graphs

This commit is contained in:
Jeremy Stretch
2016-07-20 13:56:17 -04:00
parent 65fb10059a
commit e1fc78bc44
4 changed files with 23 additions and 18 deletions

View File

@ -49,15 +49,8 @@ STATUS_ICON = """
""" """
UTILIZATION_GRAPH = """ UTILIZATION_GRAPH = """
{% with record.get_utilization as percentage %} {% load helpers %}
<div class="progress text-center"> {% utilization_graph record.get_utilization %}
{% if percentage < 15 %}<span style="font-size: 12px;">{{ percentage }}%</span>{% endif %}
<div class="progress-bar progress-bar-{% if percentage >= 90 %}danger{% elif percentage >= 75 %}warning{% else %}success{% endif %}"
role="progressbar" aria-valuenow="{{ percentage }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ percentage }}%">
{% if percentage >= 15 %}{{ percentage }}%{% endif %}
</div>
</div>
{% endwith %}
""" """

View File

@ -11,15 +11,8 @@ RIR_EDIT_LINK = """
""" """
UTILIZATION_GRAPH = """ UTILIZATION_GRAPH = """
{% with record.get_utilization as percentage %} {% load helpers %}
<div class="progress text-center"> {% utilization_graph record.get_utilization %}
{% if percentage < 15 %}<span style="font-size: 12px;">{{ percentage }}%</span>{% endif %}
<div class="progress-bar progress-bar-{% if percentage >= 90 %}danger{% elif percentage >= 75 %}warning{% else %}success{% endif %}"
role="progressbar" aria-valuenow="{{ percentage }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ percentage }}%">
{% if percentage >= 15 %}{{ percentage }}%{% endif %}
</div>
</div>
{% endwith %}
""" """
ROLE_EDIT_LINK = """ ROLE_EDIT_LINK = """

View File

@ -0,0 +1,7 @@
<div class="progress text-center">
{% if utilization < 30 %}<span style="font-size: 12px;">{{ utilization }}%</span>{% endif %}
<div class="progress-bar progress-bar-{% if utilization >= danger_threshold %}danger{% elif utilization >= warning_threshold %}warning{% else %}success{% endif %}"
role="progressbar" aria-valuenow="{{ utilization }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ utilization }}%">
{% if utilization >= 30 %}{{ utilization }}%{% endif %}
</div>
</div>

View File

@ -95,3 +95,15 @@ def querystring_toggle(request, multi=True, page_key='page', **kwargs):
return '?' + querystring return '?' + querystring
else: else:
return '' return ''
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
"""
Display a horizontal bar graph indicating a percentage of utilization.
"""
return {
'utilization': utilization,
'warning_threshold': warning_threshold,
'danger_threshold': danger_threshold,
}