From 59091efa86aec1857cb06ada4676c9a2f1903e07 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 9 Jul 2020 17:09:03 -0400 Subject: [PATCH] Closes #4840: Enable change logging for config contexts --- docs/release-notes/version-2.9.md | 1 + netbox/extras/api/serializers.py | 2 +- .../0045_configcontext_changelog.py | 23 +++++++++++++++++++ netbox/extras/models/models.py | 2 +- netbox/extras/tests/test_views.py | 1 + netbox/extras/urls.py | 3 ++- netbox/templates/extras/configcontext.html | 10 ++++++++ 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 netbox/extras/migrations/0045_configcontext_changelog.py diff --git a/docs/release-notes/version-2.9.md b/docs/release-notes/version-2.9.md index 21470aaa1..dc9139986 100644 --- a/docs/release-notes/version-2.9.md +++ b/docs/release-notes/version-2.9.md @@ -26,6 +26,7 @@ When running a report or custom script, the task is now queued for background pr * [#4807](https://github.com/netbox-community/netbox/issues/4807) - Add bulk edit ability for device bay templates * [#4817](https://github.com/netbox-community/netbox/issues/4817) - Standardize device/VM component `name` field to 64 characters * [#4837](https://github.com/netbox-community/netbox/issues/4837) - Use dynamic form widget for relationships to MPTT objects (e.g. regions) +* [#4840](https://github.com/netbox-community/netbox/issues/4840) - Enable change logging for config contexts ### Configuration Changes diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py index 2f0235e80..0d4d91a64 100644 --- a/netbox/extras/api/serializers.py +++ b/netbox/extras/api/serializers.py @@ -233,7 +233,7 @@ class ConfigContextSerializer(ValidatedModelSerializer): model = ConfigContext fields = [ 'id', 'url', 'name', 'weight', 'description', 'is_active', 'regions', 'sites', 'roles', 'platforms', - 'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags', 'data', + 'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags', 'data', 'created', 'last_updated', ] diff --git a/netbox/extras/migrations/0045_configcontext_changelog.py b/netbox/extras/migrations/0045_configcontext_changelog.py new file mode 100644 index 000000000..0368e80ee --- /dev/null +++ b/netbox/extras/migrations/0045_configcontext_changelog.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.6 on 2020-07-09 20:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0044_jobresult'), + ] + + operations = [ + migrations.AddField( + model_name='configcontext', + name='created', + field=models.DateField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name='configcontext', + name='last_updated', + field=models.DateTimeField(auto_now=True, null=True), + ), + ] diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 093589f84..edd13a123 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -434,7 +434,7 @@ class ImageAttachment(models.Model): # Config contexts # -class ConfigContext(models.Model): +class ConfigContext(ChangeLoggedModel): """ A ConfigContext represents a set of arbitrary data available to any Device or VirtualMachine matching its assigned qualifiers (region, site, etc.). For example, the data stored in a ConfigContext assigned to site A and tenant B diff --git a/netbox/extras/tests/test_views.py b/netbox/extras/tests/test_views.py index f14f02e43..cc25bef90 100644 --- a/netbox/extras/tests/test_views.py +++ b/netbox/extras/tests/test_views.py @@ -45,6 +45,7 @@ class TagTestCase(ViewTestCases.OrganizationalObjectViewTestCase): # Blocked by absence of standard create/edit, bulk create views class ConfigContextTestCase( ViewTestCases.GetObjectViewTestCase, + ViewTestCases.GetObjectChangelogViewTestCase, ViewTestCases.DeleteObjectViewTestCase, ViewTestCases.ListObjectsViewTestCase, ViewTestCases.BulkEditObjectsViewTestCase, diff --git a/netbox/extras/urls.py b/netbox/extras/urls.py index 6f8832487..36077dc7a 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 Tag +from extras.models import ConfigContext, Tag app_name = 'extras' @@ -25,6 +25,7 @@ urlpatterns = [ path('config-contexts//', views.ConfigContextView.as_view(), name='configcontext'), path('config-contexts//edit/', views.ConfigContextEditView.as_view(), name='configcontext_edit'), path('config-contexts//delete/', views.ConfigContextDeleteView.as_view(), name='configcontext_delete'), + path('config-contexts//changelog/', views.ObjectChangeLogView.as_view(), name='configcontext_changelog', kwargs={'model': ConfigContext}), # Image attachments path('image-attachments//edit/', views.ImageAttachmentEditView.as_view(), name='imageattachment_edit'), diff --git a/netbox/templates/extras/configcontext.html b/netbox/templates/extras/configcontext.html index 21e8cdab6..7dd8d8b0c 100644 --- a/netbox/templates/extras/configcontext.html +++ b/netbox/templates/extras/configcontext.html @@ -31,6 +31,16 @@ {% endif %} +

{% block title %}{{ configcontext }}{% endblock %}

{% endblock %}