Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion netbox/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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
Expand Down Expand Up @@ -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
)
4 changes: 4 additions & 0 deletions netbox/extras/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ class Meta:
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)
Expand All @@ -733,6 +735,8 @@ def __getattr__(self, item):
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):
Expand Down
12 changes: 10 additions & 2 deletions netbox/templates/extras/configrevision.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<div class="controls">
<div class="control-group">
{% 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 %}
</div>
Expand All @@ -28,6 +28,14 @@
</div>
{% endblock controls %}

{% block subtitle %}
{% if object.created %}
<div class="object-subtitle">
<span>{% trans "Created" %} {{ object.created|annotated_date }}</span>
</div>
{% endif %}
{% endblock subtitle %}

{% block content %}
<div class="row">
<div class="col col-md-12">
Expand Down