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

Introduce TenantColumn to simplify representation

This commit is contained in:
Jeremy Stretch
2021-03-04 16:07:55 -05:00
parent 23b58ccbe8
commit 20a85c1ef2
7 changed files with 48 additions and 77 deletions

View File

@ -10,13 +10,30 @@ MPTT_LINK = """
<a href="{{ record.get_absolute_url }}">{{ record.name }}</a>
"""
COL_TENANT = """
{% if record.tenant %}
<a href="{{ record.tenant.get_absolute_url }}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
{% else %}
&mdash;
{% endif %}
"""
#
# Table columns
#
class TenantColumn(tables.TemplateColumn):
"""
Render a colored label (e.g. for DeviceRoles).
"""
template_code = """
{% if record.tenant %}
<a href="{{ record.tenant.get_absolute_url }}" title="{{ record.tenant.description }}">{{ record.tenant }}</a>
{% elif record.vrf.tenant %}
<a href="{{ record.vrf.tenant.get_absolute_url }}" title="{{ record.vrf.tenant.description }}">{{ record.vrf.tenant }}</a>*
{% else %}
&mdash;
{% endif %}
"""
def __init__(self, *args, **kwargs):
super().__init__(template_code=self.template_code, *args, **kwargs)
def value(self, value):
return str(value)
#