mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00: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:
committed by
GitHub
parent
3a3d43911c
commit
ff021a8e4e
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
|
||||
)
|
||||
)
|
Reference in New Issue
Block a user