File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 22from django .shortcuts import get_object_or_404 , redirect
33
44from extras .models import ConfigRevision
5+ from netbox .config import get_config
56from netbox .views import generic
67from netbox .views .generic .base import BaseObjectView
78from utilities .utils import count_related
@@ -152,4 +153,9 @@ class ConfigView(generic.ObjectView):
152153 queryset = ConfigRevision .objects .all ()
153154
154155 def get_object (self , ** kwargs ):
155- return self .queryset .first ()
156+ if config := self .queryset .first ():
157+ return config
158+ # Instantiate a dummy default config if none has been created yet
159+ return ConfigRevision (
160+ data = get_config ().defaults
161+ )
Original file line number Diff line number Diff line change @@ -723,6 +723,8 @@ class Meta:
723723 verbose_name_plural = _ ('config revisions' )
724724
725725 def __str__ (self ):
726+ if not self .pk :
727+ return gettext ('Default configuration' )
726728 if self .is_active :
727729 return gettext ('Current configuration' )
728730 return gettext ('Config revision #{id}' ).format (id = self .pk )
@@ -733,6 +735,8 @@ def __getattr__(self, item):
733735 return super ().__getattribute__ (item )
734736
735737 def get_absolute_url (self ):
738+ if not self .pk :
739+ return reverse ('core:config' ) # Default config view
736740 return reverse ('extras:configrevision' , args = [self .pk ])
737741
738742 def activate (self ):
Original file line number Diff line number Diff line change 1414 < div class ="controls ">
1515 < div class ="control-group ">
1616 {% plugin_buttons object %}
17- {% if object.is_active and perms.extras.add_configrevision %}
17+ {% if not object.pk or object.is_active and perms.extras.add_configrevision %}
1818 {% url 'extras:configrevision_add' as edit_url %}
1919 {% include "buttons/edit.html" with url=edit_url %}
2020 {% endif %}
21- {% if not object.is_active and perms.extras.delete_configrevision %}
21+ {% if object.pk and not object.is_active and perms.extras.delete_configrevision %}
2222 {% delete_button object %}
2323 {% endif %}
2424 </ div >
2828 </ div >
2929{% endblock controls %}
3030
31+ {% block subtitle %}
32+ {% if object.created %}
33+ < div class ="object-subtitle ">
34+ < span > {% trans "Created" %} {{ object.created|annotated_date }}</ span >
35+ </ div >
36+ {% endif %}
37+ {% endblock subtitle %}
38+
3139{% block content %}
3240 < div class ="row ">
3341 < div class ="col col-md-12 ">
You can’t perform that action at this time.
0 commit comments