diff --git a/netbox/core/views.py b/netbox/core/views.py index c3e26ae3d..133396ac2 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -1,6 +1,7 @@ import json import platform +from copy import deepcopy from django import __version__ as django_version from django.conf import settings from django.contrib import messages @@ -310,6 +311,22 @@ class ConfigRevisionListView(generic.ObjectListView): class ConfigRevisionView(generic.ObjectView): queryset = ConfigRevision.objects.all() + def get_extra_context(self, request, instance): + """ + Retrieve additional context for a given request and instance. + """ + # Copy the revision data to avoid modifying the original + config = deepcopy(instance.data or {}) + + # Serialize any JSON-based classes + for attr in ['CUSTOM_VALIDATORS', 'DEFAULT_USER_PREFERENCES', 'PROTECTION_RULES']: + if attr in config: + config[attr] = json.dumps(config[attr], cls=ConfigJSONEncoder, indent=4) + + return { + 'config': config, + } + @register_model_view(ConfigRevision, 'add', detail=False) class ConfigRevisionEditView(generic.ObjectEditView): @@ -617,8 +634,8 @@ class SystemView(UserPassesTestMixin, View): response['Content-Disposition'] = 'attachment; filename="netbox.json"' return response - # Serialize any CustomValidator classes - for attr in ['CUSTOM_VALIDATORS', 'PROTECTION_RULES']: + # Serialize any JSON-based classes + for attr in ['CUSTOM_VALIDATORS', 'DEFAULT_USER_PREFERENCES', 'PROTECTION_RULES']: if hasattr(config, attr) and getattr(config, attr, None): setattr(config, attr, json.dumps(getattr(config, attr), cls=ConfigJSONEncoder, indent=4)) diff --git a/netbox/templates/core/configrevision.html b/netbox/templates/core/configrevision.html index ecb9f1c17..28179b7fd 100644 --- a/netbox/templates/core/configrevision.html +++ b/netbox/templates/core/configrevision.html @@ -33,7 +33,7 @@
{{ config.CUSTOM_VALIDATORS }}{{ config.CUSTOM_VALIDATORS }}{{ config.PROTECTION_RULES }}{{ config.PROTECTION_RULES }}{{ config.DEFAULT_USER_PREFERENCES|json }}{{ config.DEFAULT_USER_PREFERENCES }}