diff --git a/netbox/dcim/templatetags/display_region.py b/netbox/dcim/templatetags/display_region.py deleted file mode 100644 index 933d6ecbe..000000000 --- a/netbox/dcim/templatetags/display_region.py +++ /dev/null @@ -1,37 +0,0 @@ -from django import template -from django.utils.safestring import mark_safe - -register = template.Library() - - -def _display_site(obj): - """ - Render a link to the site of an object. - """ - site = getattr(obj, 'site', None) - return mark_safe('{}'.format(site.get_absolute_url(), site)) if site else None - - -@register.simple_tag(takes_context=True) -def display_region(context, obj, include_site=False): - """ - Renders hierarchical region data for a given object, optionally including the site. - """ - # Retrieve the region or site information - region = getattr(obj, 'region', None) or getattr(obj.site, 'region', None) if hasattr(obj, 'site') else None - site_link = _display_site(obj) if include_site else None - - # Return a placeholder if no region or site is found - if not region and not site_link: - return mark_safe('—') - - # Build the region links if the region is available - region_links = ' / '.join( - '{}'.format(context['request'].build_absolute_uri(reg.get_absolute_url()), reg) - for reg in region.get_ancestors(include_self=True) - ) if region else '' - - # Concatenate region and site links - links = ' / '.join(filter(None, [region_links, site_link])) - - return mark_safe(links) diff --git a/netbox/dcim/templatetags/mptt.py b/netbox/dcim/templatetags/mptt.py new file mode 100644 index 000000000..25bb58da2 --- /dev/null +++ b/netbox/dcim/templatetags/mptt.py @@ -0,0 +1,25 @@ +from django import template +from django.utils.safestring import mark_safe + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def display_region(context, obj): + """ + Renders hierarchical region data for a given object. + """ + # Retrieve the region or site information + region = getattr(obj, 'region', None) or getattr(obj.site, 'region', None) + + # Return a placeholder if no region or site is found + if not region: + return mark_safe('—') + + # Build the region links if the region is available + return mark_safe( + ' / '.join( + '{}'.format(context['request'].build_absolute_uri(reg.get_absolute_url()), reg) + for reg in region.get_ancestors(include_self=True) + ) if region else '' + ) diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 22aeb20ed..a9b31650d 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -5,7 +5,7 @@ {% load helpers %} {% load plugins %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block content %}
diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 1a3f4e4ef..d40d0c969 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -4,7 +4,7 @@ {% load static %} {% load plugins %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block content %}
@@ -16,11 +16,15 @@
- + + + + +
{% trans "Site" %}{% trans "Region" %} - {% display_region object include_site=True %} + {% display_region object %}
{% trans "Site" %}{{ object.site|linkify }}
{% trans "Location" %} diff --git a/netbox/templates/dcim/rackreservation.html b/netbox/templates/dcim/rackreservation.html index ccd64a63e..8b67b2d61 100644 --- a/netbox/templates/dcim/rackreservation.html +++ b/netbox/templates/dcim/rackreservation.html @@ -4,7 +4,7 @@ {% load static %} {% load plugins %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block breadcrumbs %} {{ block.super }} @@ -23,11 +23,15 @@ {% with rack=object.rack %} - + + + + + diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index e4b939561..fc8c78cde 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -3,7 +3,7 @@ {% load plugins %} {% load tz %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block breadcrumbs %} {{ block.super }} diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html index 399200da3..d956a5940 100644 --- a/netbox/templates/ipam/prefix.html +++ b/netbox/templates/ipam/prefix.html @@ -3,7 +3,7 @@ {% load helpers %} {% load plugins %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block content %}
@@ -46,11 +46,15 @@
- + + + + +
{% trans "Site" %}{% trans "Region" %} - {% display_region rack include_site=True %} + {% display_region rack %}
{% trans "Site" %}{{ rack.site|linkify }}
{% trans "Location" %} {{ rack.location|linkify|placeholder }}
{% trans "Site" %}{% trans "Region" %} - {% display_region object include_site=True %} + {% display_region object %}
{% trans "Site" %}{{ object.site|linkify|placeholder }}
{% trans "VLAN" %} diff --git a/netbox/templates/ipam/vlan.html b/netbox/templates/ipam/vlan.html index af70e2fad..c6bf2b765 100644 --- a/netbox/templates/ipam/vlan.html +++ b/netbox/templates/ipam/vlan.html @@ -3,7 +3,7 @@ {% load render_table from django_tables2 %} {% load plugins %} {% load i18n %} -{% load display_region %} +{% load mptt %} {% block content %}
@@ -15,11 +15,15 @@
- + + + + +
{% trans "Site" %}{% trans "Region" %} - {% display_region object include_site=True %} + {% display_region object %}
{% trans "Site" %}{{ object.site|linkify|placeholder }}
{% trans "Group" %} {{ object.group|linkify|placeholder }}