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

Introduce UtilizationColumn to render utilization graphs consistently

This commit is contained in:
Jeremy Stretch
2021-03-04 20:58:43 -05:00
parent 32501c96e5
commit e703d9ff78
4 changed files with 25 additions and 21 deletions

View File

@ -290,6 +290,9 @@ class TagColumn(tables.TemplateColumn):
class MPTTColumn(tables.TemplateColumn):
"""
Display a nested hierarchy for MPTT-enabled models.
"""
template_code = """{% for i in record.get_ancestors %}<i class="mdi mdi-circle-small"></i>{% endfor %}""" \
"""<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>"""
@ -304,3 +307,16 @@ class MPTTColumn(tables.TemplateColumn):
def value(self, value):
return value
class UtilizationColumn(tables.TemplateColumn):
"""
Display a colored utilization bar graph.
"""
template_code = """{% load helpers %}{% if record.pk %}{% utilization_graph value %}{% endif %}"""
def __init__(self, *args, **kwargs):
super().__init__(template_code=self.template_code, *args, **kwargs)
def value(self, value):
return f'{value}%'