diff --git a/netbox/core/views.py b/netbox/core/views.py index c7c593770..e3c1a67aa 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -2,6 +2,7 @@ from django.contrib import messages from django.shortcuts import get_object_or_404, redirect from extras.models import ConfigRevision +from netbox.config import get_config from netbox.views import generic from netbox.views.generic.base import BaseObjectView from utilities.utils import count_related @@ -152,4 +153,9 @@ class ConfigView(generic.ObjectView): queryset = ConfigRevision.objects.all() def get_object(self, **kwargs): - return self.queryset.first() + if config := self.queryset.first(): + return config + # Instantiate a dummy default config if none has been created yet + return ConfigRevision( + data=get_config().defaults + ) diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 91940d66e..90e8027b4 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -723,6 +723,8 @@ class ConfigRevision(models.Model): verbose_name_plural = _('config revisions') def __str__(self): + if not self.pk: + return gettext('Default configuration') if self.is_active: return gettext('Current configuration') return gettext('Config revision #{id}').format(id=self.pk) @@ -733,6 +735,8 @@ class ConfigRevision(models.Model): return super().__getattribute__(item) def get_absolute_url(self): + if not self.pk: + return reverse('core:config') # Default config view return reverse('extras:configrevision', args=[self.pk]) def activate(self): diff --git a/netbox/templates/extras/configrevision.html b/netbox/templates/extras/configrevision.html index 5937e842a..4f2abf30b 100644 --- a/netbox/templates/extras/configrevision.html +++ b/netbox/templates/extras/configrevision.html @@ -14,11 +14,11 @@
{% plugin_buttons object %} - {% if object.is_active and perms.extras.add_configrevision %} + {% if not object.pk or object.is_active and perms.extras.add_configrevision %} {% url 'extras:configrevision_add' as edit_url %} {% include "buttons/edit.html" with url=edit_url %} {% endif %} - {% if not object.is_active and perms.extras.delete_configrevision %} + {% if object.pk and not object.is_active and perms.extras.delete_configrevision %} {% delete_button object %} {% endif %}
@@ -28,6 +28,14 @@
{% endblock controls %} +{% block subtitle %} + {% if object.created %} +
+ {% trans "Created" %} {{ object.created|annotated_date }} +
+ {% endif %} +{% endblock subtitle %} + {% block content %}