Skip to content

Commit a296a9e

Browse files
committed
Closes #6150: Enable change logging for journal entries
1 parent e5bbf47 commit a296a9e

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

docs/release-notes/version-2.11.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#6121](https://github.com/netbox-community/netbox/issues/6121) - Extend parent interface assignment to VM interfaces
1111
* [#6125](https://github.com/netbox-community/netbox/issues/6125) - Add locations count to home page
1212
* [#6146](https://github.com/netbox-community/netbox/issues/6146) - Add bulk disconnect support for power feeds
13+
* [#6150](https://github.com/netbox-community/netbox/issues/6150) - Enable change logging for journal entries
1314

1415
### Bug Fixes (from Beta)
1516

netbox/extras/migrations/0058_journalentry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Migration(migrations.Migration):
1818
('id', models.BigAutoField(primary_key=True, serialize=False)),
1919
('assigned_object_id', models.PositiveIntegerField()),
2020
('created', models.DateTimeField(auto_now_add=True)),
21+
('last_updated', models.DateTimeField(auto_now=True, null=True)),
2122
('kind', models.CharField(default='info', max_length=30)),
2223
('comments', models.TextField()),
2324
('assigned_object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),

netbox/extras/models/models.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from django.core.validators import ValidationError
88
from django.db import models
99
from django.http import HttpResponse
10+
from django.urls import reverse
1011
from django.utils import timezone
12+
from django.utils.formats import date_format, time_format
1113
from rest_framework.utils.encoders import JSONEncoder
1214

1315
from extras.choices import *
1416
from extras.constants import *
1517
from extras.utils import extras_features, FeatureQuery, image_upload
16-
from netbox.models import BigIDModel
18+
from netbox.models import BigIDModel, ChangeLoggedModel
1719
from utilities.querysets import RestrictedQuerySet
1820
from utilities.utils import render_jinja2
1921

@@ -389,7 +391,7 @@ def size(self):
389391
# Journal entries
390392
#
391393

392-
class JournalEntry(BigIDModel):
394+
class JournalEntry(ChangeLoggedModel):
393395
"""
394396
A historical remark concerning an object; collectively, these form an object's journal. The journal is used to
395397
preserve historical context around an object, and complements NetBox's built-in change logging. For example, you
@@ -427,8 +429,10 @@ class Meta:
427429
verbose_name_plural = 'journal entries'
428430

429431
def __str__(self):
430-
time_created = self.created.replace(microsecond=0)
431-
return f"{time_created} - {self.get_kind_display()}"
432+
return f"{date_format(self.created)} - {time_format(self.created)} ({self.get_kind_display()})"
433+
434+
def get_absolute_url(self):
435+
return reverse('extras:journalentry', args=[self.pk])
432436

433437
def get_kind_class(self):
434438
return JournalEntryKindChoices.CSS_CLASSES.get(self.kind)

netbox/extras/tables.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ class ObjectJournalTable(BaseTable):
102102
Used for displaying a set of JournalEntries within the context of a single object.
103103
"""
104104
created = tables.DateTimeColumn(
105+
linkify=True,
105106
format=settings.SHORT_DATETIME_FORMAT
106107
)
107108
kind = ChoiceFieldColumn()
108109
comments = tables.TemplateColumn(
109-
template_code='{% load helpers %}{{ value|render_markdown }}'
110+
template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}'
110111
)
111112
actions = ButtonsColumn(
112-
model=JournalEntry,
113-
buttons=('edit', 'delete')
113+
model=JournalEntry
114114
)
115115

116116
class Meta(BaseTable.Meta):
@@ -128,9 +128,6 @@ class JournalEntryTable(ObjectJournalTable):
128128
orderable=False,
129129
verbose_name='Object'
130130
)
131-
comments = tables.TemplateColumn(
132-
template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}'
133-
)
134131

135132
class Meta(BaseTable.Meta):
136133
model = JournalEntry

netbox/extras/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.urls import path
22

33
from extras import views
4-
from extras.models import ConfigContext, Tag
4+
from extras.models import ConfigContext, JournalEntry, Tag
55

66

77
app_name = 'extras'
@@ -37,8 +37,10 @@
3737
path('journal-entries/add/', views.JournalEntryEditView.as_view(), name='journalentry_add'),
3838
path('journal-entries/edit/', views.JournalEntryBulkEditView.as_view(), name='journalentry_bulk_edit'),
3939
path('journal-entries/delete/', views.JournalEntryBulkDeleteView.as_view(), name='journalentry_bulk_delete'),
40+
path('journal-entries/<int:pk>/', views.JournalEntryView.as_view(), name='journalentry'),
4041
path('journal-entries/<int:pk>/edit/', views.JournalEntryEditView.as_view(), name='journalentry_edit'),
4142
path('journal-entries/<int:pk>/delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'),
43+
path('journal-entries/<int:pk>/changelog/', views.ObjectChangeLogView.as_view(), name='journalentry_changelog', kwargs={'model': JournalEntry}),
4244

4345
# Change logging
4446
path('changelog/', views.ObjectChangeListView.as_view(), name='objectchange_list'),

netbox/extras/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ class JournalEntryListView(generic.ObjectListView):
306306
action_buttons = ('export',)
307307

308308

309+
class JournalEntryView(generic.ObjectView):
310+
queryset = JournalEntry.objects.all()
311+
312+
309313
class JournalEntryEditView(generic.ObjectEditView):
310314
queryset = JournalEntry.objects.all()
311315
model_form = forms.JournalEntryForm
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{% extends 'generic/object.html' %}
2+
{% load helpers %}
3+
{% load static %}
4+
5+
{% block breadcrumbs %}
6+
<li><a href="{% url 'extras:journalentry_list' %}">Journal Entries</a></li>
7+
<li><a href="{% url object.assigned_object|viewname:'journal' pk=object.assigned_object.pk %}">{{ object.assigned_object }}</a></li>
8+
<li>{{ object }}</li>
9+
{% endblock %}
10+
11+
{% block content %}
12+
<div class="row">
13+
<div class="col-md-4">
14+
<div class="panel panel-default">
15+
<div class="panel-heading">
16+
<strong>Journal Entry</strong>
17+
</div>
18+
<table class="table table-hover panel-body attr-table">
19+
<tr>
20+
<td>Object</td>
21+
<td>
22+
<a href="{{ object.assigned_object.get_absolute_url }}">{{ object.assigned_object }}</a>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td>Created</td>
27+
<td>
28+
{{ object.created }}
29+
</td>
30+
</tr>
31+
<tr>
32+
<td>Created By</td>
33+
<td>
34+
{{ object.created_by }}
35+
</td>
36+
</tr>
37+
<tr>
38+
<td>Kind</td>
39+
<td>
40+
<span class="label label-{{ object.get_kind_class }}">{{ object.get_kind_display }}</span>
41+
</td>
42+
</tr>
43+
</table>
44+
</div>
45+
</div>
46+
<div class="col-md-8">
47+
<div class="panel panel-default">
48+
<div class="panel-heading">
49+
<strong>Comments</strong>
50+
</div>
51+
<div class="panel-body">
52+
{{ object.comments|render_markdown }}
53+
</div>
54+
</div>
55+
</div>
56+
</div>
57+
{% endblock %}

0 commit comments

Comments
 (0)