mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 12:42:52 -06:00
Adds region hierarchy in templates (#14213)
* initial work to render hierarchical region #13735 * adds site display #13735 * cleanup #13735 * adds display region tag #13735 * refactored region hierarchy #13735 * refactored region hierarchy #13735 * renamed display_region to nested_tree #13735 * Make render_tree suitable for generic use * Remove errant item from __all__ --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
3a3d43911c
commit
ff021a8e4e
@ -5,6 +5,7 @@
|
|||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -15,16 +16,7 @@
|
|||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Region" %}</th>
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
<td>
|
<td>{% nested_tree object.site.region %}</td>
|
||||||
{% if object.site.region %}
|
|
||||||
{% for region in object.site.region.get_ancestors %}
|
|
||||||
{{ region|linkify }} /
|
|
||||||
{% endfor %}
|
|
||||||
{{ object.site.region|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Site" %}</th>
|
<th scope="row">{% trans "Site" %}</th>
|
||||||
@ -32,16 +24,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Location" %}</th>
|
<th scope="row">{% trans "Location" %}</th>
|
||||||
<td>
|
<td>{% nested_tree object.location %}</td>
|
||||||
{% if object.location %}
|
|
||||||
{% for location in object.location.get_ancestors %}
|
|
||||||
{{ location|linkify }} /
|
|
||||||
{% endfor %}
|
|
||||||
{{ object.location|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Rack" %}</th>
|
<th scope="row">{% trans "Rack" %}</th>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -15,26 +16,18 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Site" %}</th>
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.site.region %}
|
{% nested_tree object.site.region %}
|
||||||
{{ object.site.region|linkify }} /
|
|
||||||
{% endif %}
|
|
||||||
{{ object.site|linkify }}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Site" %}</th>
|
||||||
|
<td>{{ object.site|linkify }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Location" %}</th>
|
<th scope="row">{% trans "Location" %}</th>
|
||||||
<td>
|
<td>{% nested_tree object.location %}</td>
|
||||||
{% if object.location %}
|
|
||||||
{% for location in object.location.get_ancestors %}
|
|
||||||
{{ location|linkify }} /
|
|
||||||
{% endfor %}
|
|
||||||
{{ object.location|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Facility ID" %}</th>
|
<th scope="row">{% trans "Facility ID" %}</th>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
@ -20,25 +21,24 @@
|
|||||||
</h5>
|
</h5>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
{% with rack=object.rack %}
|
<tr>
|
||||||
<tr>
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
<th scope="row">{% trans "Site" %}</th>
|
<td>
|
||||||
<td>
|
{% nested_tree object.rack.site.region %}
|
||||||
{% if rack.site.region %}
|
</td>
|
||||||
{{ rack.site.region|linkify }} /
|
</tr>
|
||||||
{% endif %}
|
<tr>
|
||||||
{{ rack.site|linkify }}
|
<th scope="row">{% trans "Site" %}</th>
|
||||||
</td>
|
<td>{{ object.rack.site|linkify }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Location" %}</th>
|
<th scope="row">{% trans "Location" %}</th>
|
||||||
<td>{{ rack.location|linkify|placeholder }}</td>
|
<td>{{ object.rack.location|linkify|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Rack" %}</th>
|
<th scope="row">{% trans "Rack" %}</th>
|
||||||
<td>{{ rack|linkify }}</td>
|
<td>{{ object.rack|linkify }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endwith %}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load tz %}
|
{% load tz %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block breadcrumbs %}
|
{% block breadcrumbs %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
@ -29,27 +30,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Region" %}</th>
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.region %}
|
{% nested_tree object.region %}
|
||||||
{% for region in object.region.get_ancestors %}
|
|
||||||
{{ region|linkify }} /
|
|
||||||
{% endfor %}
|
|
||||||
{{ object.region|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Group" %}</th>
|
<th scope="row">{% trans "Group" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.group %}
|
{% nested_tree object.group %}
|
||||||
{% for group in object.group.get_ancestors %}
|
|
||||||
{{ group|linkify }} /
|
|
||||||
{% endfor %}
|
|
||||||
{{ object.group|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -44,18 +45,17 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if object.site.region %}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
|
<td>
|
||||||
|
{% nested_tree object.site.region %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Site" %}</th>
|
<th scope="row">{% trans "Site" %}</th>
|
||||||
<td>
|
<td>{{ object.site|linkify|placeholder }}</td>
|
||||||
{% if object.site %}
|
|
||||||
{% if object.site.region %}
|
|
||||||
{{ object.site.region|linkify }} /
|
|
||||||
{% endif %}
|
|
||||||
{{ object.site|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "VLAN" %}</th>
|
<th scope="row">{% trans "VLAN" %}</th>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
{% load render_table from django_tables2 %}
|
{% load render_table from django_tables2 %}
|
||||||
{% load plugins %}
|
{% load plugins %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load mptt %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -13,18 +14,17 @@
|
|||||||
</h5>
|
</h5>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
|
{% if object.site.region %}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans "Region" %}</th>
|
||||||
|
<td>
|
||||||
|
{% nested_tree object.site.region %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Site" %}</th>
|
<th scope="row">{% trans "Site" %}</th>
|
||||||
<td>
|
<td>{{ object.site|linkify|placeholder }}</td>
|
||||||
{% if object.site %}
|
|
||||||
{% if object.site.region %}
|
|
||||||
{{ object.site.region|linkify }} /
|
|
||||||
{% endif %}
|
|
||||||
{{ object.site|linkify }}
|
|
||||||
{% else %}
|
|
||||||
{{ ''|placeholder }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Group" %}</th>
|
<th scope="row">{% trans "Group" %}</th>
|
||||||
|
20
netbox/utilities/templatetags/mptt.py
Normal file
20
netbox/utilities/templatetags/mptt.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from django import template
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag()
|
||||||
|
def nested_tree(obj):
|
||||||
|
"""
|
||||||
|
Renders the entire hierarchy of a recursively-nested object (such as Region or SiteGroup).
|
||||||
|
"""
|
||||||
|
if not obj:
|
||||||
|
return mark_safe('—')
|
||||||
|
|
||||||
|
nodes = obj.get_ancestors(include_self=True)
|
||||||
|
return mark_safe(
|
||||||
|
' / '.join(
|
||||||
|
f'<a href="{node.get_absolute_url()}">{node}</a>' for node in nodes
|
||||||
|
)
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user