Skip to content

Commit 0c04fbb

Browse files
committed
feat(templates): Add breadcrumbs for rule templates
Replaces manual `<a>` tags with the `linkify` filter for consistent linking. Adds breadcrumbs for better navigation and includes return URLs for object actions. Refactors various details table rows for clarity and maintainability. Fixes #243
1 parent f43974b commit 0c04fbb

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

netbox_acls/templates/netbox_acls/accesslist.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
{% extends 'generic/object.html' %}
22
{% load render_table from django_tables2 %}
3+
{% load helpers %}
34

45
{% block extra_controls %}
56
{% if perms.netbox_acls.change_policy %}
7+
{% with viewname=object|viewname:"" %}
68
{% if object.type == 'extended' %}
7-
<a href="{% url 'plugins:netbox_acls:aclextendedrule_add' %}?access_list={{ object.pk }}" class="btn btn-primary">
9+
<a href="{% url 'plugins:netbox_acls:aclextendedrule_add' %}?access_list={{ object.pk }}&return_url={% url viewname pk=object.pk %}" class="btn btn-primary">
810
{% elif object.type == 'standard' %}
9-
<a href="{% url 'plugins:netbox_acls:aclstandardrule_add' %}?access_list={{ object.pk }}" class="btn btn-primary">
11+
<a href="{% url 'plugins:netbox_acls:aclstandardrule_add' %}?access_list={{ object.pk }}&return_url={% url viewname pk=object.pk %}" class="btn btn-primary">
1012
{% endif %}
1113
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> Rule
1214
</a>
15+
{% endwith %}
1316
{% endif %}
1417
{% endblock extra_controls %}
1518

@@ -31,11 +34,11 @@ <h2 class="card-header">Access List</h2>
3134
<th scope="row">Rules</th>
3235
{% if object.type == 'standard' %}
3336
<td>
34-
<a href="{% url 'plugins:netbox_acls:aclstandardrule_list' %}?access_list={{ object.pk }}">{{ object.aclstandardrules.count|placeholder }}</a>
37+
<a href="{% url 'plugins:netbox_acls:aclstandardrule_list' %}?access_list_id={{ object.pk }}">{{ object.aclstandardrules.count|placeholder }}</a>
3538
</td>
3639
{% elif object.type == 'extended' %}
3740
<td>
38-
<a href="{% url 'plugins:netbox_acls:aclextendedrule_list' %}?access_list={{ object.pk }}">{{ object.aclextendedrules.count|placeholder }}</a>
41+
<a href="{% url 'plugins:netbox_acls:aclextendedrule_list' %}?access_list_id={{ object.pk }}">{{ object.aclextendedrules.count|placeholder }}</a>
3942
</td>
4043
{% endif %}
4144
</tr>

netbox_acls/templates/netbox_acls/aclextendedrule.html

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{% extends 'generic/object.html' %}
22

3+
{% block breadcrumbs %}
4+
{{ block.super }}
5+
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_acls:aclextendedrule_list' %}?access_list_id={{ object.access_list.pk }}">{{ object.access_list }}</a></li>
6+
{% endblock breadcrumbs %}
7+
38
{% block content %}
49
<div class="row mb-3">
510
<div class="col col-md-6">
@@ -8,9 +13,7 @@ <h2 class="card-header">ACL Extended Rule</h2>
813
<table class="table table-hover attr-table">
914
<tr>
1015
<th scope="row">Access List</th>
11-
<td>
12-
<a href="{{ object.access_list.get_absolute_url }}">{{ object.access_list }}</a>
13-
</td>
16+
<td>{{ object.access_list|linkify }}</td>
1417
</tr>
1518
<tr>
1619
<th scope="row">Description</th>
@@ -29,46 +32,34 @@ <h2 class="card-header">ACL Extended Rule</h2>
2932
<div class="card">
3033
<h2 class="card-header">Details</h2>
3134
<table class="table table-hover attr-table">
35+
<tr>
36+
<th scope="row">Action</th>
37+
<td>{% badge object.get_action_display bg_color=object.get_action_color %}</td>
38+
</tr>
3239
<tr>
3340
<th scope="row">Remark</th>
34-
<td>{{ object.get_remark_display|placeholder }}</td>
41+
<td>{{ object.remark|placeholder }}</td>
3542
</tr>
3643
<tr>
3744
<th scope="row">Protocol</th>
3845
<td>{{ object.get_protocol_display|placeholder }}</td>
3946
</tr>
4047
<tr>
4148
<th scope="row">Source Prefix</th>
42-
<td>
43-
{% if object.source_prefix %}
44-
<a href="{{ object.source_prefix.get_absolute_url }}">{{ object.source_prefix }}</a>
45-
{% else %}
46-
{{ ''|placeholder }}
47-
{% endif %}
48-
</td>
49+
<td>{{ object.source_prefix|linkify|placeholder }}</td>
4950
</tr>
5051
<tr>
5152
<th scope="row">Source Ports</th>
5253
<td>{{ object.source_ports|join:", "|placeholder }}</td>
5354
</tr>
5455
<tr>
5556
<th scope="row">Destination Prefix</th>
56-
<td>
57-
{% if object.destination_prefix %}
58-
<a href="{{ object.destination_prefix.get_absolute_url }}">{{ object.destination_prefix }}</a>
59-
{% else %}
60-
{{ ''|placeholder }}
61-
{% endif %}
62-
</td>
57+
<td>{{ object.destination_prefix|linkify|placeholder }}</td>
6358
</tr>
6459
<tr>
6560
<th scope="row">Destination Ports</th>
6661
<td>{{ object.destination_ports|join:", "|placeholder }}</td>
6762
</tr>
68-
<tr>
69-
<th scope="row">Action</th>
70-
<td>{% badge object.get_action_display bg_color=object.get_action_color %}</td>
71-
</tr>
7263
</table>
7364
</div>
7465
</div>

netbox_acls/templates/netbox_acls/aclinterfaceassignment.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{% extends 'generic/object.html' %}
22
{% load render_table from django_tables2 %}
33

4+
{% block breadcrumbs %}
5+
{{ block.super }}
6+
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_acls:aclinterfaceassignment_list' %}?access_list_id={{ object.access_list.pk }}">{{ object.access_list }}</a></li>
7+
{% endblock breadcrumbs %}
8+
49
{% block content %}
510
<div class="row mb-3">
611
<div class="col col-md-6">
@@ -11,23 +16,19 @@ <h2 class="card-header">ACL Interface Assignment</h2>
1116
<th scope="row">Host</th>
1217
<td>
1318
{% if object.assigned_object.device %}
14-
<a href="{{ object.assigned_object.device.get_absolute_url }}">{{ object.assigned_object.device|placeholder }}</a>
19+
{{ object.assigned_object.device|linkify|placeholder }}
1520
{% else %}
16-
<a href="{{ object.assigned_object.virtual_machine.get_absolute_url }}">{{ object.assigned_object.virtual_machine|placeholder }}</a>
21+
{{ object.assigned_object.virtual_machine|linkify|placeholder }}
1722
{% endif %}
1823
</td>
1924
</tr>
2025
<tr>
2126
<th scope="row">Interface</th>
22-
<td>
23-
<a href="{{ object.assigned_object.get_absolute_url }}">{{ object.assigned_object }}</a>
24-
</td>
27+
<td>{{ object.assigned_object|linkify|placeholder }}</td>
2528
</tr>
2629
<tr>
2730
<th scope="row">Access List</th>
28-
<td>
29-
<a href="{{ object.access_list.get_absolute_url }}">{{ object.access_list }}</a>
30-
</td>
31+
<td>{{ object.access_list|linkify }}</td>
3132
</tr>
3233
<tr>
3334
<th scope="row">Direction</th>

netbox_acls/templates/netbox_acls/aclstandardrule.html

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{% extends 'generic/object.html' %}
22

3+
{% block breadcrumbs %}
4+
{{ block.super }}
5+
<li class="breadcrumb-item"><a href="{% url 'plugins:netbox_acls:aclstandardrule_list' %}?access_list_id={{ object.access_list.pk }}">{{ object.access_list }}</a></li>
6+
{% endblock breadcrumbs %}
7+
38
{% block content %}
49
<div class="row mb-3">
510
<div class="col col-md-6">
@@ -8,9 +13,7 @@ <h2 class="card-header">ACL Standard Rule</h2>
813
<table class="table table-hover attr-table">
914
<tr>
1015
<th scope="row">Access List</th>
11-
<td>
12-
<a href="{{ object.access_list.get_absolute_url }}">{{ object.access_list }}</a>
13-
</td>
16+
<td>{{ object.access_list|linkify }}</td>
1417
</tr>
1518
<tr>
1619
<th scope="row">Index</th>
@@ -30,26 +33,16 @@ <h2 class="card-header">ACL Standard Rule</h2>
3033
<h2 class="card-header">Details</h2>
3134
<table class="table table-hover attr-table">
3235
<tr>
33-
<th scope="row">Remark</th>
34-
<td>{{ object.get_remark_display|placeholder }}</td>
36+
<th scope="row">Action</th>
37+
<td>{% badge object.get_action_display bg_color=object.get_action_color %}</td>
3538
</tr>
3639
<tr>
37-
<th scope="row">Protocol</th>
38-
<td>{{ object.get_protocol_display|placeholder }}</td>
40+
<th scope="row">Remark</th>
41+
<td>{{ object.remark|placeholder }}</td>
3942
</tr>
4043
<tr>
4144
<th scope="row">Source Prefix</th>
42-
<td>
43-
{% if object.source_prefix %}
44-
<a href="{{ object.source_prefix.get_absolute_url }}">{{ object.source_prefix }}</a>
45-
{% else %}
46-
{{ ''|placeholder }}
47-
{% endif %}
48-
</td>
49-
</tr>
50-
<tr>
51-
<th scope="row">Action</th>
52-
<td>{% badge object.get_action_display bg_color=object.get_action_color %}</td>
45+
<td>{{ object.source_prefix|linkify|placeholder }}</td>
5346
</tr>
5447
</table>
5548
</div>

0 commit comments

Comments
 (0)