diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 7ab536c673..0afda238a0 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -10,6 +10,7 @@ * [#6121](https://github.com/netbox-community/netbox/issues/6121) - Extend parent interface assignment to VM interfaces * [#6125](https://github.com/netbox-community/netbox/issues/6125) - Add locations count to home page * [#6146](https://github.com/netbox-community/netbox/issues/6146) - Add bulk disconnect support for power feeds +* [#6150](https://github.com/netbox-community/netbox/issues/6150) - Enable change logging for journal entries ### Bug Fixes (from Beta) diff --git a/netbox/extras/migrations/0058_journalentry.py b/netbox/extras/migrations/0058_journalentry.py index 14be2a50d8..22abf965ca 100644 --- a/netbox/extras/migrations/0058_journalentry.py +++ b/netbox/extras/migrations/0058_journalentry.py @@ -18,6 +18,7 @@ class Migration(migrations.Migration): ('id', models.BigAutoField(primary_key=True, serialize=False)), ('assigned_object_id', models.PositiveIntegerField()), ('created', models.DateTimeField(auto_now_add=True)), + ('last_updated', models.DateTimeField(auto_now=True, null=True)), ('kind', models.CharField(default='info', max_length=30)), ('comments', models.TextField()), ('assigned_object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')), diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 3209a7037d..41bc345e2d 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -7,13 +7,15 @@ from django.core.validators import ValidationError from django.db import models from django.http import HttpResponse +from django.urls import reverse from django.utils import timezone +from django.utils.formats import date_format, time_format from rest_framework.utils.encoders import JSONEncoder from extras.choices import * from extras.constants import * from extras.utils import extras_features, FeatureQuery, image_upload -from netbox.models import BigIDModel +from netbox.models import BigIDModel, ChangeLoggedModel from utilities.querysets import RestrictedQuerySet from utilities.utils import render_jinja2 @@ -389,7 +391,7 @@ def size(self): # Journal entries # -class JournalEntry(BigIDModel): +class JournalEntry(ChangeLoggedModel): """ A historical remark concerning an object; collectively, these form an object's journal. The journal is used to preserve historical context around an object, and complements NetBox's built-in change logging. For example, you @@ -427,8 +429,10 @@ class Meta: verbose_name_plural = 'journal entries' def __str__(self): - time_created = self.created.replace(microsecond=0) - return f"{time_created} - {self.get_kind_display()}" + return f"{date_format(self.created)} - {time_format(self.created)} ({self.get_kind_display()})" + + def get_absolute_url(self): + return reverse('extras:journalentry', args=[self.pk]) def get_kind_class(self): return JournalEntryKindChoices.CSS_CLASSES.get(self.kind) diff --git a/netbox/extras/tables.py b/netbox/extras/tables.py index a8efd8005a..dd7b45c6f8 100644 --- a/netbox/extras/tables.py +++ b/netbox/extras/tables.py @@ -102,15 +102,15 @@ class ObjectJournalTable(BaseTable): Used for displaying a set of JournalEntries within the context of a single object. """ created = tables.DateTimeColumn( + linkify=True, format=settings.SHORT_DATETIME_FORMAT ) kind = ChoiceFieldColumn() comments = tables.TemplateColumn( - template_code='{% load helpers %}{{ value|render_markdown }}' + template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}' ) actions = ButtonsColumn( - model=JournalEntry, - buttons=('edit', 'delete') + model=JournalEntry ) class Meta(BaseTable.Meta): @@ -128,9 +128,6 @@ class JournalEntryTable(ObjectJournalTable): orderable=False, verbose_name='Object' ) - comments = tables.TemplateColumn( - template_code='{% load helpers %}{{ value|render_markdown|truncatewords_html:50 }}' - ) class Meta(BaseTable.Meta): model = JournalEntry diff --git a/netbox/extras/urls.py b/netbox/extras/urls.py index f38a2ecd35..9ec19d215b 100644 --- a/netbox/extras/urls.py +++ b/netbox/extras/urls.py @@ -1,7 +1,7 @@ from django.urls import path from extras import views -from extras.models import ConfigContext, Tag +from extras.models import ConfigContext, JournalEntry, Tag app_name = 'extras' @@ -37,8 +37,10 @@ path('journal-entries/add/', views.JournalEntryEditView.as_view(), name='journalentry_add'), path('journal-entries/edit/', views.JournalEntryBulkEditView.as_view(), name='journalentry_bulk_edit'), path('journal-entries/delete/', views.JournalEntryBulkDeleteView.as_view(), name='journalentry_bulk_delete'), + path('journal-entries//', views.JournalEntryView.as_view(), name='journalentry'), path('journal-entries//edit/', views.JournalEntryEditView.as_view(), name='journalentry_edit'), path('journal-entries//delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'), + path('journal-entries//changelog/', views.ObjectChangeLogView.as_view(), name='journalentry_changelog', kwargs={'model': JournalEntry}), # Change logging path('changelog/', views.ObjectChangeListView.as_view(), name='objectchange_list'), diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 4b62604b92..4cda84d994 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -306,6 +306,10 @@ class JournalEntryListView(generic.ObjectListView): action_buttons = ('export',) +class JournalEntryView(generic.ObjectView): + queryset = JournalEntry.objects.all() + + class JournalEntryEditView(generic.ObjectEditView): queryset = JournalEntry.objects.all() model_form = forms.JournalEntryForm diff --git a/netbox/templates/extras/journalentry.html b/netbox/templates/extras/journalentry.html new file mode 100644 index 0000000000..f64741f36a --- /dev/null +++ b/netbox/templates/extras/journalentry.html @@ -0,0 +1,57 @@ +{% extends 'generic/object.html' %} +{% load helpers %} +{% load static %} + +{% block breadcrumbs %} +
  • Journal Entries
  • +
  • {{ object.assigned_object }}
  • +
  • {{ object }}
  • +{% endblock %} + +{% block content %} +
    +
    +
    +
    + Journal Entry +
    + + + + + + + + + + + + + + + + + +
    Object + {{ object.assigned_object }} +
    Created + {{ object.created }} +
    Created By + {{ object.created_by }} +
    Kind + {{ object.get_kind_display }} +
    +
    +
    +
    +
    +
    + Comments +
    +
    + {{ object.comments|render_markdown }} +
    +
    +
    +
    +{% endblock %}