refactored region hierarchy #13735

This commit is contained in:
Abhimanyu Saharan 2023-11-09 21:04:16 +05:30
parent f615eec28c
commit d97449560f

View File

@ -1,5 +1,6 @@
from django import template from django import template
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from dcim.models import Site
register = template.Library() register = template.Library()
@ -10,6 +11,9 @@ def display_region(context, obj):
Renders hierarchical region data for a given object. Renders hierarchical region data for a given object.
""" """
# Retrieve the region or site information # Retrieve the region or site information
if isinstance(obj, Site):
region = obj.region
else:
region = getattr(obj, 'region', None) or getattr(obj.site, 'region', None) region = getattr(obj, 'region', None) or getattr(obj.site, 'region', None)
# Return a placeholder if no region or site is found # Return a placeholder if no region or site is found