Sfoglia il codice sorgente

Update ObjectChangeLogView to use "object" context var

Jeremy Stretch 5 anni fa
parent
commit
3e7cf416f1

+ 1 - 1
netbox/dcim/urls.py

@@ -197,7 +197,7 @@ urlpatterns = [
     path('devices/<int:pk>/device-bays/', views.DeviceDeviceBaysView.as_view(), name='device_devicebays'),
     path('devices/<int:pk>/device-bays/', views.DeviceDeviceBaysView.as_view(), name='device_devicebays'),
     path('devices/<int:pk>/inventory/', views.DeviceInventoryView.as_view(), name='device_inventory'),
     path('devices/<int:pk>/inventory/', views.DeviceInventoryView.as_view(), name='device_inventory'),
     path('devices/<int:pk>/config-context/', views.DeviceConfigContextView.as_view(), name='device_configcontext'),
     path('devices/<int:pk>/config-context/', views.DeviceConfigContextView.as_view(), name='device_configcontext'),
-    path('devices/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='device_changelog', kwargs={'model': Device}),
+    path('devices/<int:pk>/changelog/', views.DeviceChangeLogView.as_view(), name='device_changelog', kwargs={'model': Device}),
     path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
     path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
     path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
     path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
     path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),
     path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),

+ 5 - 1
netbox/dcim/views.py

@@ -12,7 +12,7 @@ from django.utils.safestring import mark_safe
 from django.views.generic import View
 from django.views.generic import View
 
 
 from circuits.models import Circuit
 from circuits.models import Circuit
-from extras.views import ObjectConfigContextView
+from extras.views import ObjectChangeLogView, ObjectConfigContextView
 from ipam.models import IPAddress, Prefix, Service, VLAN
 from ipam.models import IPAddress, Prefix, Service, VLAN
 from ipam.tables import InterfaceIPAddressTable, InterfaceVLANTable
 from ipam.tables import InterfaceIPAddressTable, InterfaceVLANTable
 from netbox.views import generic
 from netbox.views import generic
@@ -1288,6 +1288,10 @@ class DeviceConfigContextView(ObjectConfigContextView):
     base_template = 'dcim/device/base.html'
     base_template = 'dcim/device/base.html'
 
 
 
 
+class DeviceChangeLogView(ObjectChangeLogView):
+    base_template = 'dcim/device/base.html'
+
+
 class DeviceEditView(generic.ObjectEditView):
 class DeviceEditView(generic.ObjectEditView):
     queryset = Device.objects.all()
     queryset = Device.objects.all()
     model_form = forms.DeviceForm
     model_form = forms.DeviceForm

+ 7 - 10
netbox/extras/views.py

@@ -228,7 +228,10 @@ class ObjectChangeView(generic.ObjectView):
 class ObjectChangeLogView(View):
 class ObjectChangeLogView(View):
     """
     """
     Present a history of changes made to a particular object.
     Present a history of changes made to a particular object.
+
+    base_template: The name of the template to extend. If not provided, "<app>/<model>.html" will be used.
     """
     """
+    base_template = None
 
 
     def get(self, request, model, **kwargs):
     def get(self, request, model, **kwargs):
 
 
@@ -259,19 +262,13 @@ class ObjectChangeLogView(View):
         RequestConfig(request, paginate).configure(objectchanges_table)
         RequestConfig(request, paginate).configure(objectchanges_table)
 
 
         # Check whether a header template exists for this model
         # Check whether a header template exists for this model
-        base_template = '{}/{}.html'.format(model._meta.app_label, model._meta.model_name)
-        try:
-            template.loader.get_template(base_template)
-            object_var = model._meta.model_name
-        except template.TemplateDoesNotExist:
-            base_template = 'base.html'
-            object_var = 'obj'
+        if self.base_template is None:
+            self.base_template = f"{model._meta.app_label}/{model._meta.model_name}.html"
 
 
         return render(request, 'extras/object_changelog.html', {
         return render(request, 'extras/object_changelog.html', {
-            object_var: obj,
-            'instance': obj,  # We'll eventually standardize on 'instance` for the object variable name
+            'object': obj,
             'table': objectchanges_table,
             'table': objectchanges_table,
-            'base_template': base_template,
+            'base_template': self.base_template,
             'active_tab': 'changelog',
             'active_tab': 'changelog',
         })
         })
 
 

+ 1 - 2
netbox/templates/extras/object_changelog.html

@@ -1,9 +1,8 @@
 {% extends base_template %}
 {% extends base_template %}
 
 
-{% block title %}{% if obj %}{{ obj }}{% else %}{{ block.super }}{% endif %} - Change Log{% endblock %}
+{% block title %}{{ block.super }} - Change Log{% endblock %}
 
 
 {% block content %}
 {% block content %}
-    {% if obj %}<h1>{{ obj }}</h1>{% endif %}
     {% include 'panel_table.html' %}
     {% include 'panel_table.html' %}
     {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
     {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
     <div class="text-muted">
     <div class="text-muted">