Skip to content

Commit

Permalink
Closes #6150: Enable change logging for journal entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Apr 13, 2021
1 parent e5bbf47 commit a296a9e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-2.11.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions netbox/extras/migrations/0058_journalentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
12 changes: 8 additions & 4 deletions netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions netbox/extras/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion netbox/extras/urls.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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/<int:pk>/', views.JournalEntryView.as_view(), name='journalentry'),
path('journal-entries/<int:pk>/edit/', views.JournalEntryEditView.as_view(), name='journalentry_edit'),
path('journal-entries/<int:pk>/delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'),
path('journal-entries/<int:pk>/changelog/', views.ObjectChangeLogView.as_view(), name='journalentry_changelog', kwargs={'model': JournalEntry}),

# Change logging
path('changelog/', views.ObjectChangeListView.as_view(), name='objectchange_list'),
Expand Down
4 changes: 4 additions & 0 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions netbox/templates/extras/journalentry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends 'generic/object.html' %}
{% load helpers %}
{% load static %}

{% block breadcrumbs %}
<li><a href="{% url 'extras:journalentry_list' %}">Journal Entries</a></li>
<li><a href="{% url object.assigned_object|viewname:'journal' pk=object.assigned_object.pk %}">{{ object.assigned_object }}</a></li>
<li>{{ object }}</li>
{% endblock %}

{% block content %}
<div class="row">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Journal Entry</strong>
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>Object</td>
<td>
<a href="{{ object.assigned_object.get_absolute_url }}">{{ object.assigned_object }}</a>
</td>
</tr>
<tr>
<td>Created</td>
<td>
{{ object.created }}
</td>
</tr>
<tr>
<td>Created By</td>
<td>
{{ object.created_by }}
</td>
</tr>
<tr>
<td>Kind</td>
<td>
<span class="label label-{{ object.get_kind_class }}">{{ object.get_kind_display }}</span>
</td>
</tr>
</table>
</div>
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Comments</strong>
</div>
<div class="panel-body">
{{ object.comments|render_markdown }}
</div>
</div>
</div>
</div>
{% endblock %}

0 comments on commit a296a9e

Please sign in to comment.