From e6b3983a4e37ab2e2ed96c410cad844b9282c821 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 18 May 2018 11:09:11 -0400 Subject: [PATCH] Added template tag for tag links --- netbox/templates/circuits/circuit.html | 8 +++++++- netbox/templates/circuits/provider.html | 8 +++++++- netbox/templates/dcim/device.html | 8 +++++++- netbox/templates/dcim/devicetype.html | 8 +++++++- netbox/templates/dcim/rack.html | 8 +++++++- netbox/templates/dcim/site.html | 8 +++++++- netbox/templates/ipam/aggregate.html | 9 ++++++++- netbox/templates/ipam/ipaddress.html | 9 ++++++++- netbox/templates/ipam/prefix.html | 8 +++++++- netbox/templates/ipam/vlan.html | 9 ++++++++- netbox/templates/ipam/vrf.html | 9 ++++++++- netbox/templates/secrets/secret.html | 9 ++++++++- netbox/templates/tenancy/tenant.html | 8 +++++++- netbox/templates/utilities/templatetags/tag.html | 1 + netbox/templates/virtualization/cluster.html | 8 +++++++- netbox/templates/virtualization/virtualmachine.html | 8 +++++++- netbox/utilities/templatetags/helpers.py | 12 +++++++++++- 17 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 netbox/templates/utilities/templatetags/tag.html diff --git a/netbox/templates/circuits/circuit.html b/netbox/templates/circuits/circuit.html index 34d467c89..509c6da89 100644 --- a/netbox/templates/circuits/circuit.html +++ b/netbox/templates/circuits/circuit.html @@ -112,7 +112,13 @@ Tags - {{ circuit.tags.all|join:" " }} + + {% for tag in circuit.tags.all %} + {% tag 'circuits:circuit_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/circuits/provider.html b/netbox/templates/circuits/provider.html index 583d1da4d..e19175c7f 100644 --- a/netbox/templates/circuits/provider.html +++ b/netbox/templates/circuits/provider.html @@ -104,7 +104,13 @@ Tags - {{ provider.tags.all|join:" " }} + + {% for tag in provider.tags.all %} + {% tag 'circuits:provider_list' tag %} + {% empty %} + N/A + {% endfor %} + Circuits diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 69c408494..1b1d3d23a 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -98,7 +98,13 @@ Tags - {{ device.tags.all|join:" " }} + + {% for tag in device.tags.all %} + {% tag 'dcim:device_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index f169d9c8c..27d2e3694 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -75,7 +75,13 @@ Tags - {{ devicetype.tags.all|join:" " }} + + {% for tag in devicetype.tags.all %} + {% tag 'dcim:devicetype_list' tag %} + {% empty %} + N/A + {% endfor %} + Instances diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 3acd0ad46..82348e6fe 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -116,7 +116,13 @@ Tags - {{ rack.tags.all|join:" " }} + + {% for tag in rack.tags.all %} + {% tag 'dcim:rack_list' tag %} + {% empty %} + N/A + {% endfor %} + Devices diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index 4eaaf08cf..a882d77c8 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -135,7 +135,13 @@ Tags - {{ site.tags.all|join:" " }} + + {% for tag in site.tags.all %} + {% tag 'dcim:site_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/ipam/aggregate.html b/netbox/templates/ipam/aggregate.html index de32e9c00..a7711354d 100644 --- a/netbox/templates/ipam/aggregate.html +++ b/netbox/templates/ipam/aggregate.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load helpers %} {% block content %}
@@ -83,7 +84,13 @@ Tags - {{ aggregate.tags.all|join:" " }} + + {% for tag in aggregate.tags.all %} + {% tag 'ipam:aggregate_list' tag %} + {% empty %} + N/A + {% endfor %} +
diff --git a/netbox/templates/ipam/ipaddress.html b/netbox/templates/ipam/ipaddress.html index c6002eb02..da0fc6923 100644 --- a/netbox/templates/ipam/ipaddress.html +++ b/netbox/templates/ipam/ipaddress.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load helpers %} {% block content %}
@@ -135,7 +136,13 @@ Tags - {{ ipaddress.tags.all|join:" " }} + + {% for tag in ipaddress.tags.all %} + {% tag 'ipam:ipaddress_list' tag %} + {% empty %} + N/A + {% endfor %} +
diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html index 466fcc92d..29e9c07a0 100644 --- a/netbox/templates/ipam/prefix.html +++ b/netbox/templates/ipam/prefix.html @@ -123,7 +123,13 @@ Tags - {{ prefix.tags.all|join:" " }} + + {% for tag in prefix.tags.all %} + {% tag 'ipam:prefix_list' tag %} + {% empty %} + N/A + {% endfor %} + Utilization diff --git a/netbox/templates/ipam/vlan.html b/netbox/templates/ipam/vlan.html index 817f0e6b5..ac874282f 100644 --- a/netbox/templates/ipam/vlan.html +++ b/netbox/templates/ipam/vlan.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load helpers %} {% block content %} {% include 'ipam/inc/vlan_header.html' with active_tab='vlan' %} @@ -83,7 +84,13 @@ Tags - {{ vlan.tags.all|join:" " }} + + {% for tag in vlan.tags.all %} + {% tag 'ipam:vlan_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/ipam/vrf.html b/netbox/templates/ipam/vrf.html index 51088a0ec..fa51a18f8 100644 --- a/netbox/templates/ipam/vrf.html +++ b/netbox/templates/ipam/vrf.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load helpers %} {% block content %}
@@ -80,7 +81,13 @@ Tags - {{ vrf.tags.all|join:" " }} + + {% for tag in vrf.tags.all %} + {% tag 'ipam:vrf_list' tag %} + {% empty %} + N/A + {% endfor %} +
diff --git a/netbox/templates/secrets/secret.html b/netbox/templates/secrets/secret.html index e9e333ee7..4863fdeb1 100644 --- a/netbox/templates/secrets/secret.html +++ b/netbox/templates/secrets/secret.html @@ -1,5 +1,6 @@ {% extends '_base.html' %} {% load static from staticfiles %} +{% load helpers %} {% load secret_helpers %} {% block content %} @@ -57,7 +58,13 @@ Tags - {{ secret.tags.all|join:" " }} + + {% for tag in secret.tags.all %} + {% tag 'secrets:secret_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/tenancy/tenant.html b/netbox/templates/tenancy/tenant.html index bf7f5ed67..fbbac175a 100644 --- a/netbox/templates/tenancy/tenant.html +++ b/netbox/templates/tenancy/tenant.html @@ -70,7 +70,13 @@ Tags - {{ tenant.tags.all|join:" " }} + + {% for tag in tenant.tags.all %} + {% tag 'tenancy:tenant_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/templates/utilities/templatetags/tag.html b/netbox/templates/utilities/templatetags/tag.html new file mode 100644 index 000000000..79e1627db --- /dev/null +++ b/netbox/templates/utilities/templatetags/tag.html @@ -0,0 +1 @@ +{{ tag }} diff --git a/netbox/templates/virtualization/cluster.html b/netbox/templates/virtualization/cluster.html index 05031dff0..9b1621530 100644 --- a/netbox/templates/virtualization/cluster.html +++ b/netbox/templates/virtualization/cluster.html @@ -78,7 +78,13 @@ Tags - {{ cluster.tags.all|join:" " }} + + {% for tag in cluster.tags.all %} + {% tag 'virtualization:cluster_list' tag %} + {% empty %} + N/A + {% endfor %} + Virtual Machines diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index c8d119528..430caafca 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -123,7 +123,13 @@ Tags - {{ vm.tags.all|join:" " }} + + {% for tag in vm.tags.all %} + {% tag 'virtualization:vm_list' tag %} + {% empty %} + N/A + {% endfor %} + diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 7d79a5f2a..1380941b3 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import datetime -import pytz from django import template from django.utils.safestring import mark_safe @@ -160,3 +159,14 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90): 'warning_threshold': warning_threshold, 'danger_threshold': danger_threshold, } + + +@register.inclusion_tag('utilities/templatetags/tag.html') +def tag(url_name, tag): + """ + Display a link to the given object list filtered by a specific Tag slug. + """ + return { + 'url_name': url_name, + 'tag': tag, + }