Update ObjectChangeLogView to use "object" context var

This commit is contained in:
Jeremy Stretch 2020-11-19 11:49:37 -05:00
parent e2d2ff8586
commit 3e7cf416f1
4 changed files with 14 additions and 14 deletions

View File

@ -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'),

View File

@ -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

View File

@ -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) if self.base_template is None:
try: self.base_template = f"{model._meta.app_label}/{model._meta.model_name}.html"
template.loader.get_template(base_template)
object_var = model._meta.model_name
except template.TemplateDoesNotExist:
base_template = 'base.html'
object_var = 'obj'
return render(request, 'extras/object_changelog.html', { return render(request, 'extras/object_changelog.html', {
object_var: obj, 'object': obj,
'instance': obj, # We'll eventually standardize on 'instance` for the object variable name
'table': objectchanges_table, 'table': objectchanges_table,
'base_template': base_template, 'base_template': self.base_template,
'active_tab': 'changelog', 'active_tab': 'changelog',
}) })

View File

@ -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">