Skip to content

Commit 7f36b87

Browse files
authored
Merge pull request #142 from netboxlabs/NPL-386-journal-2
NPL-386 Add journaling support and support NetBox _get_action_url changes
2 parents 39e6941 + 3a5a21f commit 7f36b87

File tree

5 files changed

+309
-41
lines changed

5 files changed

+309
-41
lines changed

netbox_custom_objects/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ def get_list_url(self):
133133
kwargs={"custom_object_type": self.custom_object_type.name.lower()},
134134
)
135135

136+
@classmethod
137+
def _get_viewname(cls, action=None, rest_api=False):
138+
if rest_api:
139+
return f"plugins-api:netbox_custom_objects:api:customobject_{action}"
140+
return f"plugins:netbox_custom_objects:customobject_{action}"
141+
142+
@classmethod
143+
def _get_action_url(cls, action=None, rest_api=False, kwargs=None):
144+
if kwargs:
145+
kwargs["custom_object_type"] = cls.custom_object_type.name.lower()
146+
return reverse(cls._get_viewname(action, rest_api), kwargs=kwargs)
147+
136148

137149
class CustomObjectType(PrimaryModel):
138150
# Class-level cache for generated models

netbox_custom_objects/templates/netbox_custom_objects/customobject.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@
7373
<li class="nav-item">
7474
<a class="nav-link{% if not tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object.custom_object_type.get_verbose_name }}</a>
7575
</li>
76-
77-
{# Include tabs for registered model views #}
78-
{% model_view_tabs object %}
76+
<li class="nav-item">
77+
<a class="nav-link{% if tab == 'journal' %} active{% endif %}" href="{% url 'plugins:netbox_custom_objects:customobject_journal' object.custom_object_type.name object.pk %}">{% trans "Journal" %}</a>
78+
</li>
79+
<li class="nav-item">
80+
<a class="nav-link{% if tab == 'changelog' %} active{% endif %}" href="{% url 'plugins:netbox_custom_objects:customobject_changelog' object.custom_object_type.name object.pk %}">{% trans "Changelog" %}</a>
81+
</li>
7982
</ul>
8083
{% endblock tabs %}
8184

@@ -145,4 +148,4 @@ <h2 class="card-header">{{ field }}</h2>
145148
{% plugin_full_width_page object %}
146149
</div>
147150
</div>
148-
{% endblock %}
151+
{% endblock %}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% extends base_template %}
2+
{% load form_helpers %}
3+
{% load render_table from django_tables2 %}
4+
{% load i18n %}
5+
6+
{% render_errors form %}
7+
8+
{% block content %}
9+
<div class="card">
10+
<div class="table-responsive">
11+
{% render_table table 'inc/table.html' %}
12+
{% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
13+
</div>
14+
</div>
15+
{% if perms.extras.add_journalentry %}
16+
<div class="card">
17+
<h2 class="card-header">{% trans "New Journal Entry" %}</h2>
18+
<div class="card-body">
19+
<form action="{% if form_action %}{{ form_action }}{% else %}{% url 'extras:journalentry_add' %}{% endif %}" method="post" enctype="multipart/form-data">
20+
<div class="container">
21+
<div class="field-group">
22+
{% csrf_token %}
23+
{% render_form form %}
24+
</div>
25+
<div class="col col-md-12 text-end my-3">
26+
<a href="{{ object.get_absolute_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
27+
<button type="submit" class="btn btn-primary">{% trans "Save" %}</button>
28+
</div>
29+
</div>
30+
</form>
31+
</div>
32+
</div>
33+
{% endif %}
34+
{% endblock %}

netbox_custom_objects/urls.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121
name="customobjecttypefield_add",
2222
),
2323

24-
# Custom Objects1
24+
# Journal Entries (must come before custom object patterns)
25+
path(
26+
"journal-entries/add/",
27+
views.CustomJournalEntryEditView.as_view(),
28+
name="custom_journalentry_add",
29+
),
30+
31+
# Custom Objects
2532
path(
2633
"<str:custom_object_type>/",
2734
views.CustomObjectListView.as_view(),
@@ -57,4 +64,14 @@
5764
views.CustomObjectDeleteView.as_view(),
5865
name="customobject_delete",
5966
),
67+
path(
68+
"<str:custom_object_type>/<int:pk>/journal/",
69+
views.CustomObjectJournalView.as_view(),
70+
name="customobject_journal",
71+
),
72+
path(
73+
"<str:custom_object_type>/<int:pk>/changelog/",
74+
views.CustomObjectChangeLogView.as_view(),
75+
name="customobject_changelog",
76+
),
6077
]

0 commit comments

Comments
 (0)