File tree 7 files changed +73
-90
lines changed 7 files changed +73
-90
lines changed Original file line number Diff line number Diff line change 5
5
{% load helpers %}
6
6
{% load plugins %}
7
7
{% load i18n %}
8
+ {% load mptt %}
8
9
9
10
{% block content %}
10
11
< div class ="row ">
@@ -15,33 +16,15 @@ <h5 class="card-header">{% trans "Device" %}</h5>
15
16
< table class ="table table-hover attr-table ">
16
17
< tr >
17
18
< th scope ="row "> {% trans "Region" %}</ th >
18
- < td >
19
- {% if object.site.region %}
20
- {% for region in object.site.region.get_ancestors %}
21
- {{ region|linkify }} /
22
- {% endfor %}
23
- {{ object.site.region|linkify }}
24
- {% else %}
25
- {{ ''|placeholder }}
26
- {% endif %}
27
- </ td >
19
+ < td > {% nested_tree object.site.region %}</ td >
28
20
</ tr >
29
21
< tr >
30
22
< th scope ="row "> {% trans "Site" %}</ th >
31
23
< td > {{ object.site|linkify }}</ td >
32
24
</ tr >
33
25
< tr >
34
26
< th scope ="row "> {% trans "Location" %}</ th >
35
- < td >
36
- {% if object.location %}
37
- {% for location in object.location.get_ancestors %}
38
- {{ location|linkify }} /
39
- {% endfor %}
40
- {{ object.location|linkify }}
41
- {% else %}
42
- {{ ''|placeholder }}
43
- {% endif %}
44
- </ td >
27
+ < td > {% nested_tree object.location %}</ td >
45
28
</ tr >
46
29
< tr >
47
30
< th scope ="row "> {% trans "Rack" %}</ th >
Original file line number Diff line number Diff line change 4
4
{% load static %}
5
5
{% load plugins %}
6
6
{% load i18n %}
7
+ {% load mptt %}
7
8
8
9
{% block content %}
9
10
< div class ="row ">
@@ -15,26 +16,18 @@ <h5 class="card-header">
15
16
< div class ="card-body ">
16
17
< table class ="table table-hover attr-table ">
17
18
< tr >
18
- < th scope ="row "> {% trans "Site " %}</ th >
19
+ < th scope ="row "> {% trans "Region " %}</ th >
19
20
< td >
20
- {% if object.site.region %}
21
- {{ object.site.region|linkify }} /
22
- {% endif %}
23
- {{ object.site|linkify }}
21
+ {% nested_tree object.site.region %}
24
22
</ td >
25
23
</ tr >
24
+ < tr >
25
+ < th scope ="row "> {% trans "Site" %}</ th >
26
+ < td > {{ object.site|linkify }}</ td >
27
+ </ tr >
26
28
< tr >
27
29
< th scope ="row "> {% trans "Location" %}</ th >
28
- < td >
29
- {% if object.location %}
30
- {% for location in object.location.get_ancestors %}
31
- {{ location|linkify }} /
32
- {% endfor %}
33
- {{ object.location|linkify }}
34
- {% else %}
35
- {{ ''|placeholder }}
36
- {% endif %}
37
- </ td >
30
+ < td > {% nested_tree object.location %}</ td >
38
31
</ tr >
39
32
< tr >
40
33
< th scope ="row "> {% trans "Facility ID" %}</ th >
Original file line number Diff line number Diff line change 4
4
{% load static %}
5
5
{% load plugins %}
6
6
{% load i18n %}
7
+ {% load mptt %}
7
8
8
9
{% block breadcrumbs %}
9
10
{{ block.super }}
@@ -20,25 +21,24 @@ <h5 class="card-header">
20
21
</ h5 >
21
22
< div class ="card-body ">
22
23
< table class ="table table-hover attr-table ">
23
- {% with rack=object.rack %}
24
- < tr >
25
- < th scope ="row "> {% trans "Site" %}</ th >
26
- < td >
27
- {% if rack.site.region %}
28
- {{ rack.site.region|linkify }} /
29
- {% endif %}
30
- {{ rack.site|linkify }}
31
- </ td >
32
- </ tr >
33
- < tr >
34
- < th scope ="row "> {% trans "Location" %}</ th >
35
- < td > {{ rack.location|linkify|placeholder }}</ td >
36
- </ tr >
37
- < tr >
38
- < th scope ="row "> {% trans "Rack" %}</ th >
39
- < td > {{ rack|linkify }}</ td >
40
- </ tr >
41
- {% endwith %}
24
+ < tr >
25
+ < th scope ="row "> {% trans "Region" %}</ th >
26
+ < td >
27
+ {% nested_tree object.rack.site.region %}
28
+ </ td >
29
+ </ tr >
30
+ < tr >
31
+ < th scope ="row "> {% trans "Site" %}</ th >
32
+ < td > {{ object.rack.site|linkify }}</ td >
33
+ </ tr >
34
+ < tr >
35
+ < th scope ="row "> {% trans "Location" %}</ th >
36
+ < td > {{ object.rack.location|linkify|placeholder }}</ td >
37
+ </ tr >
38
+ < tr >
39
+ < th scope ="row "> {% trans "Rack" %}</ th >
40
+ < td > {{ object.rack|linkify }}</ td >
41
+ </ tr >
42
42
</ table >
43
43
</ div >
44
44
</ div >
Original file line number Diff line number Diff line change 3
3
{% load plugins %}
4
4
{% load tz %}
5
5
{% load i18n %}
6
+ {% load mptt %}
6
7
7
8
{% block breadcrumbs %}
8
9
{{ block.super }}
@@ -29,27 +30,13 @@ <h5 class="card-header">{% trans "Site" %}</h5>
29
30
< tr >
30
31
< th scope ="row "> {% trans "Region" %}</ th >
31
32
< td >
32
- {% if object.region %}
33
- {% for region in object.region.get_ancestors %}
34
- {{ region|linkify }} /
35
- {% endfor %}
36
- {{ object.region|linkify }}
37
- {% else %}
38
- {{ ''|placeholder }}
39
- {% endif %}
33
+ {% nested_tree object.region %}
40
34
</ td >
41
35
</ tr >
42
36
< tr >
43
37
< th scope ="row "> {% trans "Group" %}</ th >
44
38
< td >
45
- {% if object.group %}
46
- {% for group in object.group.get_ancestors %}
47
- {{ group|linkify }} /
48
- {% endfor %}
49
- {{ object.group|linkify }}
50
- {% else %}
51
- {{ ''|placeholder }}
52
- {% endif %}
39
+ {% nested_tree object.group %}
53
40
</ td >
54
41
</ tr >
55
42
< tr >
Original file line number Diff line number Diff line change 3
3
{% load helpers %}
4
4
{% load plugins %}
5
5
{% load i18n %}
6
+ {% load mptt %}
6
7
7
8
{% block content %}
8
9
< div class ="row ">
@@ -44,18 +45,17 @@ <h5 class="card-header">{% trans "Prefix" %}</h5>
44
45
{% endif %}
45
46
</ td >
46
47
</ tr >
48
+ {% if object.site.region %}
49
+ < tr >
50
+ < th scope ="row "> {% trans "Region" %}</ th >
51
+ < td >
52
+ {% nested_tree object.site.region %}
53
+ </ td >
54
+ </ tr >
55
+ {% endif %}
47
56
< tr >
48
57
< th scope ="row "> {% trans "Site" %}</ th >
49
- < td >
50
- {% if object.site %}
51
- {% if object.site.region %}
52
- {{ object.site.region|linkify }} /
53
- {% endif %}
54
- {{ object.site|linkify }}
55
- {% else %}
56
- {{ ''|placeholder }}
57
- {% endif %}
58
- </ td >
58
+ < td > {{ object.site|linkify|placeholder }}</ td >
59
59
</ tr >
60
60
< tr >
61
61
< th scope ="row "> {% trans "VLAN" %}</ th >
Original file line number Diff line number Diff line change 3
3
{% load render_table from django_tables2 %}
4
4
{% load plugins %}
5
5
{% load i18n %}
6
+ {% load mptt %}
6
7
7
8
{% block content %}
8
9
< div class ="row ">
@@ -13,18 +14,17 @@ <h5 class="card-header">
13
14
</ h5 >
14
15
< div class ="card-body ">
15
16
< table class ="table table-hover attr-table ">
17
+ {% if object.site.region %}
18
+ < tr >
19
+ < th scope ="row "> {% trans "Region" %}</ th >
20
+ < td >
21
+ {% nested_tree object.site.region %}
22
+ </ td >
23
+ </ tr >
24
+ {% endif %}
16
25
< tr >
17
26
< th scope ="row "> {% trans "Site" %}</ th >
18
- < td >
19
- {% if object.site %}
20
- {% if object.site.region %}
21
- {{ object.site.region|linkify }} /
22
- {% endif %}
23
- {{ object.site|linkify }}
24
- {% else %}
25
- {{ ''|placeholder }}
26
- {% endif %}
27
- </ td >
27
+ < td > {{ object.site|linkify|placeholder }}</ td >
28
28
</ tr >
29
29
< tr >
30
30
< th scope ="row "> {% trans "Group" %}</ th >
Original file line number Diff line number Diff line change
1
+ from django import template
2
+ from django .utils .safestring import mark_safe
3
+
4
+ register = template .Library ()
5
+
6
+
7
+ @register .simple_tag ()
8
+ def nested_tree (obj ):
9
+ """
10
+ Renders the entire hierarchy of a recursively-nested object (such as Region or SiteGroup).
11
+ """
12
+ if not obj :
13
+ return mark_safe ('—' )
14
+
15
+ nodes = obj .get_ancestors (include_self = True )
16
+ return mark_safe (
17
+ ' / ' .join (
18
+ f'<a href="{ node .get_absolute_url ()} ">{ node } </a>' for node in nodes
19
+ )
20
+ )
You can’t perform that action at this time.
0 commit comments