Skip to content

Commit 7a9a45c

Browse files
author
Jan Krupa
committed
Apply CodeRabbit review fixes: add preferences to error context, reformat templates
- Add missing "preferences" key to error_context in typed tab view - Reformat all 4 templates with djlint (4-space indent) - Fix ruff E501 line-length in test file
1 parent 37ccf6b commit 7a9a45c

6 files changed

Lines changed: 468 additions & 443 deletions

File tree

netbox_custom_objects_tab/templates/netbox_custom_objects/customobject.html

Lines changed: 130 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -11,150 +11,150 @@
1111
{% load custom_object_utils %}
1212
{% block extra_controls %}{% endblock %}
1313
{% block breadcrumbs %}
14-
<li class="breadcrumb-item">
15-
<a href="{{ object.get_list_url }}">{{ object.custom_object_type.get_verbose_name_plural }}</a>
16-
</li>
17-
<li class="breadcrumb-item">
18-
<a href="{{ object.custom_object_type.get_absolute_url }}">{{ object.custom_object_type }}</a>
19-
</li>
14+
<li class="breadcrumb-item">
15+
<a href="{{ object.get_list_url }}">{{ object.custom_object_type.get_verbose_name_plural }}</a>
16+
</li>
17+
<li class="breadcrumb-item">
18+
<a href="{{ object.custom_object_type.get_absolute_url }}">{{ object.custom_object_type }}</a>
19+
</li>
2020
{% endblock breadcrumbs %}
2121
{% block object_identifier %}
22-
{{ object|meta:"app_label" }}.{{ object.custom_object_type.slug }}:{{ object.pk }}
23-
{% if object.slug %}({{ object.slug }}){% endif %}
22+
{{ object|meta:"app_label" }}.{{ object.custom_object_type.slug }}:{{ object.pk }}
23+
{% if object.slug %}({{ object.slug }}){% endif %}
2424
{% endblock object_identifier %}
2525
{% block title %}
26-
{{ object }}
26+
{{ object }}
2727
{% endblock title %}
2828
{% block subtitle %}
29-
<div class="text-secondary fs-5">
30-
{% trans "Created" %} {{ object.created|isodatetime:"minutes" }}
31-
{% if object.last_updated %}
32-
<span class="separator">·</span>
33-
{% trans "Updated" %} {{ object.last_updated|isodatetime:"minutes" }}
34-
{% endif %}
35-
</div>
29+
<div class="text-secondary fs-5">
30+
{% trans "Created" %} {{ object.created|isodatetime:"minutes" }}
31+
{% if object.last_updated %}
32+
<span class="separator">·</span>
33+
{% trans "Updated" %} {{ object.last_updated|isodatetime:"minutes" }}
34+
{% endif %}
35+
</div>
3636
{% endblock subtitle %}
3737
{% block controls %}
38-
<div class="btn-list justify-content-end mb-2">
39-
{% block control-buttons %}
40-
{# Default buttons #}
41-
{% if perms.extras.add_bookmark and object.bookmarks %}
42-
{% custom_object_bookmark_button object %}
43-
{% endif %}
44-
{% if perms.extras.add_subscription and object.subscriptions %}
45-
{% custom_object_subscribe_button object %}
46-
{% endif %}
47-
{% if request.user|can_add:object %}
48-
{% custom_object_clone_button object %}
49-
{% endif %}
50-
{% if request.user|can_change:object %}
51-
{% custom_object_edit_button object %}
52-
{% endif %}
53-
{% if request.user|can_delete:object %}
54-
{% custom_object_delete_button object %}
55-
{% endif %}
56-
{% endblock %}
57-
</div>
58-
{# Custom links #}
59-
<div class="d-flex justify-content-end">
60-
<div class="btn-list">
61-
{% block custom-links %}
62-
{% custom_links object %}
63-
{% endblock custom-links %}
38+
<div class="btn-list justify-content-end mb-2">
39+
{% block control-buttons %}
40+
{# Default buttons #}
41+
{% if perms.extras.add_bookmark and object.bookmarks %}
42+
{% custom_object_bookmark_button object %}
43+
{% endif %}
44+
{% if perms.extras.add_subscription and object.subscriptions %}
45+
{% custom_object_subscribe_button object %}
46+
{% endif %}
47+
{% if request.user|can_add:object %}
48+
{% custom_object_clone_button object %}
49+
{% endif %}
50+
{% if request.user|can_change:object %}
51+
{% custom_object_edit_button object %}
52+
{% endif %}
53+
{% if request.user|can_delete:object %}
54+
{% custom_object_delete_button object %}
55+
{% endif %}
56+
{% endblock %}
57+
</div>
58+
{# Custom links #}
59+
<div class="d-flex justify-content-end">
60+
<div class="btn-list">
61+
{% block custom-links %}
62+
{% custom_links object %}
63+
{% endblock custom-links %}
64+
</div>
6465
</div>
65-
</div>
6666
{% endblock controls %}
6767
{% block tabs %}
68-
<ul class="nav nav-tabs" role="presentation">
69-
{# Primary tab #}
70-
<li class="nav-item">
71-
<a class="nav-link{% if not tab %} active{% endif %}"
72-
href="{{ object.get_absolute_url }}">{{ object.custom_object_type.get_verbose_name }}</a>
73-
</li>
74-
{# All other tabs (Journal, Changelog, Custom Objects, typed tabs) come from the registry #}
75-
{% model_view_tabs object %}
76-
</ul>
68+
<ul class="nav nav-tabs" role="presentation">
69+
{# Primary tab #}
70+
<li class="nav-item">
71+
<a class="nav-link{% if not tab %} active{% endif %}"
72+
href="{{ object.get_absolute_url }}">{{ object.custom_object_type.get_verbose_name }}</a>
73+
</li>
74+
{# All other tabs (Journal, Changelog, Custom Objects, typed tabs) come from the registry #}
75+
{% model_view_tabs object %}
76+
</ul>
7777
{% endblock tabs %}
7878
{% block content %}
79-
<div class="row">
80-
<div class="col col-md-6">
81-
<div class="card">
82-
<table class="table table-hover attr-table">
83-
<tr>
84-
<th scope="row">{% trans "Type" %}</th>
85-
<td>{{ object.custom_object_type|linkify:"display_name" }}</td>
86-
</tr>
87-
<tr>
88-
<th scope="row">{% trans "Last activity" %}</th>
89-
<td>
90-
{{ latest_change.time|isodatetime|placeholder }}
91-
{% if latest_change %}
92-
<div class="small text-muted">{{ latest_change.time|timesince }} {% trans "ago" %}</div>
93-
{% endif %}
94-
</td>
95-
</tr>
96-
{% for group_name, group_fields in field_groups.items %}
97-
{% if group_name %}
98-
<tr class="table-group-header">
99-
<th scope="row" colspan="2" class="fw-bold">{{ group_name }}</th>
100-
</tr>
101-
{% endif %}
102-
{% for field in group_fields %}
103-
{% with is_visible_in_ui=object|get_field_is_ui_visible:field %}
104-
{% if field.is_single_value and is_visible_in_ui %}
105-
<tr>
106-
<th scope="row">
107-
{{ field }}
108-
{% if field.description %}
109-
<i class="mdi mdi-information text-primary"
110-
data-bs-toggle="tooltip"
111-
data-bs-placement="right"
112-
title="{{ field.description|escape }}"></i>
113-
{% endif %}
114-
</th>
115-
<td>
116-
{% with customfield=field value=object|get_field_value:field %}
117-
{% include "builtins/customfield_value.html" %}
118-
{% endwith %}
119-
</td>
120-
</tr>
121-
{% endif %}
122-
{% endwith %}
79+
<div class="row">
80+
<div class="col col-md-6">
81+
<div class="card">
82+
<table class="table table-hover attr-table">
83+
<tr>
84+
<th scope="row">{% trans "Type" %}</th>
85+
<td>{{ object.custom_object_type|linkify:"display_name" }}</td>
86+
</tr>
87+
<tr>
88+
<th scope="row">{% trans "Last activity" %}</th>
89+
<td>
90+
{{ latest_change.time|isodatetime|placeholder }}
91+
{% if latest_change %}
92+
<div class="small text-muted">{{ latest_change.time|timesince }} {% trans "ago" %}</div>
93+
{% endif %}
94+
</td>
95+
</tr>
96+
{% for group_name, group_fields in field_groups.items %}
97+
{% if group_name %}
98+
<tr class="table-group-header">
99+
<th scope="row" colspan="2" class="fw-bold">{{ group_name }}</th>
100+
</tr>
101+
{% endif %}
102+
{% for field in group_fields %}
103+
{% with is_visible_in_ui=object|get_field_is_ui_visible:field %}
104+
{% if field.is_single_value and is_visible_in_ui %}
105+
<tr>
106+
<th scope="row">
107+
{{ field }}
108+
{% if field.description %}
109+
<i class="mdi mdi-information text-primary"
110+
data-bs-toggle="tooltip"
111+
data-bs-placement="right"
112+
title="{{ field.description|escape }}"></i>
113+
{% endif %}
114+
</th>
115+
<td>
116+
{% with customfield=field value=object|get_field_value:field %}
117+
{% include "builtins/customfield_value.html" %}
118+
{% endwith %}
119+
</td>
120+
</tr>
121+
{% endif %}
122+
{% endwith %}
123+
{% endfor %}
124+
{% endfor %}
125+
</table>
126+
</div>
127+
{% plugin_left_page object %}
128+
</div>
129+
<div class="col col-md-6">
130+
{% include 'inc/panels/tags.html' %}
131+
{% plugin_right_page object %}
132+
{% for group_name, group_fields in field_groups.items %}
133+
{% for field in group_fields %}
134+
{% if field.many %}
135+
{% with field_values=object|get_child_relations:field is_visible_in_ui=object|get_field_is_ui_visible:field %}
136+
{% if is_visible_in_ui %}
137+
<div class="card">
138+
<h2 class="card-header">
139+
{% if group_name %}{{ group_name }}:{% endif %}
140+
{{ field }}
141+
</h2>
142+
<table class="table table-hover attr-table">
143+
{% for relation in field_values.all %}
144+
<tr>
145+
<th scope="row">{{ relation|linkify }}</th>
146+
</tr>
147+
{% endfor %}
148+
</table>
149+
</div>
150+
{% endif %}
151+
{% endwith %}
152+
{% endif %}
153+
{% endfor %}
123154
{% endfor %}
124-
{% endfor %}
125-
</table>
126-
</div>
127-
{% plugin_left_page object %}
155+
</div>
128156
</div>
129-
<div class="col col-md-6">
130-
{% include 'inc/panels/tags.html' %}
131-
{% plugin_right_page object %}
132-
{% for group_name, group_fields in field_groups.items %}
133-
{% for field in group_fields %}
134-
{% if field.many %}
135-
{% with field_values=object|get_child_relations:field is_visible_in_ui=object|get_field_is_ui_visible:field %}
136-
{% if is_visible_in_ui %}
137-
<div class="card">
138-
<h2 class="card-header">
139-
{% if group_name %}{{ group_name }}:{% endif %}
140-
{{ field }}
141-
</h2>
142-
<table class="table table-hover attr-table">
143-
{% for relation in field_values.all %}
144-
<tr>
145-
<th scope="row">{{ relation|linkify }}</th>
146-
</tr>
147-
{% endfor %}
148-
</table>
149-
</div>
150-
{% endif %}
151-
{% endwith %}
152-
{% endif %}
153-
{% endfor %}
154-
{% endfor %}
157+
<div class="row mb-3">
158+
<div class="col col-md-12">{% plugin_full_width_page object %}</div>
155159
</div>
156-
</div>
157-
<div class="row mb-3">
158-
<div class="col col-md-12">{% plugin_full_width_page object %}</div>
159-
</div>
160160
{% endblock %}

0 commit comments

Comments
 (0)