mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #7530: Move device type component lists to separate views
This commit is contained in:
@@ -435,6 +435,116 @@ class DeviceTypeTestCase(
|
||||
'is_full_depth': False,
|
||||
}
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_consoleports(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
console_ports = (
|
||||
ConsolePortTemplate(device_type=devicetype, name='Console Port 1'),
|
||||
ConsolePortTemplate(device_type=devicetype, name='Console Port 2'),
|
||||
ConsolePortTemplate(device_type=devicetype, name='Console Port 3'),
|
||||
)
|
||||
ConsolePortTemplate.objects.bulk_create(console_ports)
|
||||
|
||||
url = reverse('dcim:devicetype_consoleports', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_consoleserverports(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
console_server_ports = (
|
||||
ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 1'),
|
||||
ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 2'),
|
||||
ConsoleServerPortTemplate(device_type=devicetype, name='Console Server Port 3'),
|
||||
)
|
||||
ConsoleServerPortTemplate.objects.bulk_create(console_server_ports)
|
||||
|
||||
url = reverse('dcim:devicetype_consoleserverports', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_powerports(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
power_ports = (
|
||||
PowerPortTemplate(device_type=devicetype, name='Power Port 1'),
|
||||
PowerPortTemplate(device_type=devicetype, name='Power Port 2'),
|
||||
PowerPortTemplate(device_type=devicetype, name='Power Port 3'),
|
||||
)
|
||||
PowerPortTemplate.objects.bulk_create(power_ports)
|
||||
|
||||
url = reverse('dcim:devicetype_powerports', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_poweroutlets(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
power_outlets = (
|
||||
PowerOutletTemplate(device_type=devicetype, name='Power Outlet 1'),
|
||||
PowerOutletTemplate(device_type=devicetype, name='Power Outlet 2'),
|
||||
PowerOutletTemplate(device_type=devicetype, name='Power Outlet 3'),
|
||||
)
|
||||
PowerOutletTemplate.objects.bulk_create(power_outlets)
|
||||
|
||||
url = reverse('dcim:devicetype_poweroutlets', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_interfaces(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
interfaces = (
|
||||
InterfaceTemplate(device_type=devicetype, name='Interface 1'),
|
||||
InterfaceTemplate(device_type=devicetype, name='Interface 2'),
|
||||
InterfaceTemplate(device_type=devicetype, name='Interface 3'),
|
||||
)
|
||||
InterfaceTemplate.objects.bulk_create(interfaces)
|
||||
|
||||
url = reverse('dcim:devicetype_interfaces', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_rearports(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
rear_ports = (
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 1'),
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 2'),
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 3'),
|
||||
)
|
||||
RearPortTemplate.objects.bulk_create(rear_ports)
|
||||
|
||||
url = reverse('dcim:devicetype_rearports', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_frontports(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
rear_ports = (
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 1'),
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 2'),
|
||||
RearPortTemplate(device_type=devicetype, name='Rear Port 3'),
|
||||
)
|
||||
RearPortTemplate.objects.bulk_create(rear_ports)
|
||||
front_ports = (
|
||||
FrontPortTemplate(device_type=devicetype, name='Front Port 1', rear_port=rear_ports[0], rear_port_position=1),
|
||||
FrontPortTemplate(device_type=devicetype, name='Front Port 2', rear_port=rear_ports[1], rear_port_position=1),
|
||||
FrontPortTemplate(device_type=devicetype, name='Front Port 3', rear_port=rear_ports[2], rear_port_position=1),
|
||||
)
|
||||
FrontPortTemplate.objects.bulk_create(front_ports)
|
||||
|
||||
url = reverse('dcim:devicetype_frontports', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_devicetype_devicebays(self):
|
||||
devicetype = DeviceType.objects.first()
|
||||
device_bays = (
|
||||
DeviceBayTemplate(device_type=devicetype, name='Device Bay 1'),
|
||||
DeviceBayTemplate(device_type=devicetype, name='Device Bay 2'),
|
||||
DeviceBayTemplate(device_type=devicetype, name='Device Bay 3'),
|
||||
)
|
||||
DeviceBayTemplate.objects.bulk_create(device_bays)
|
||||
|
||||
url = reverse('dcim:devicetype_devicebays', kwargs={'pk': devicetype.pk})
|
||||
self.assertHttpStatus(self.client.get(url), 200)
|
||||
|
||||
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
|
||||
def test_import_objects(self):
|
||||
"""
|
||||
|
@@ -109,6 +109,14 @@ urlpatterns = [
|
||||
path('device-types/edit/', views.DeviceTypeBulkEditView.as_view(), name='devicetype_bulk_edit'),
|
||||
path('device-types/delete/', views.DeviceTypeBulkDeleteView.as_view(), name='devicetype_bulk_delete'),
|
||||
path('device-types/<int:pk>/', views.DeviceTypeView.as_view(), name='devicetype'),
|
||||
path('device-types/<int:pk>/console-ports/', views.DeviceTypeConsolePortsView.as_view(), name='devicetype_consoleports'),
|
||||
path('device-types/<int:pk>/console-server-ports/', views.DeviceTypeConsoleServerPortsView.as_view(), name='devicetype_consoleserverports'),
|
||||
path('device-types/<int:pk>/power-ports/', views.DeviceTypePowerPortsView.as_view(), name='devicetype_powerports'),
|
||||
path('device-types/<int:pk>/power-outlets/', views.DeviceTypePowerOutletsView.as_view(), name='devicetype_poweroutlets'),
|
||||
path('device-types/<int:pk>/interfaces/', views.DeviceTypeInterfacesView.as_view(), name='devicetype_interfaces'),
|
||||
path('device-types/<int:pk>/front-ports/', views.DeviceTypeFrontPortsView.as_view(), name='devicetype_frontports'),
|
||||
path('device-types/<int:pk>/rear-ports/', views.DeviceTypeRearPortsView.as_view(), name='devicetype_rearports'),
|
||||
path('device-types/<int:pk>/device-bays/', views.DeviceTypeDeviceBaysView.as_view(), name='devicetype_devicebays'),
|
||||
path('device-types/<int:pk>/edit/', views.DeviceTypeEditView.as_view(), name='devicetype_edit'),
|
||||
path('device-types/<int:pk>/delete/', views.DeviceTypeDeleteView.as_view(), name='devicetype_delete'),
|
||||
path('device-types/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='devicetype_changelog', kwargs={'model': DeviceType}),
|
||||
|
@@ -54,11 +54,19 @@ class DeviceComponentsView(generic.ObjectView):
|
||||
paginate_table(table, request)
|
||||
|
||||
return {
|
||||
f'{self.model._meta.model_name}_table': table,
|
||||
'table': table,
|
||||
'active_tab': f"{self.model._meta.verbose_name_plural.replace(' ', '-')}",
|
||||
}
|
||||
|
||||
|
||||
class DeviceTypeComponentsView(DeviceComponentsView):
|
||||
queryset = DeviceType.objects.all()
|
||||
template_name = 'dcim/devicetype/component_templates.html'
|
||||
|
||||
def get_components(self, request, instance):
|
||||
return self.model.objects.restrict(request.user, 'view').filter(device_type=instance)
|
||||
|
||||
|
||||
class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View):
|
||||
"""
|
||||
An extendable view for disconnection console/power/interface components in bulk.
|
||||
@@ -782,62 +790,52 @@ class DeviceTypeView(generic.ObjectView):
|
||||
def get_extra_context(self, request, instance):
|
||||
instance_count = Device.objects.restrict(request.user).filter(device_type=instance).count()
|
||||
|
||||
# Component tables
|
||||
consoleport_table = tables.ConsolePortTemplateTable(
|
||||
ConsolePortTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
consoleserverport_table = tables.ConsoleServerPortTemplateTable(
|
||||
ConsoleServerPortTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
powerport_table = tables.PowerPortTemplateTable(
|
||||
PowerPortTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
poweroutlet_table = tables.PowerOutletTemplateTable(
|
||||
PowerOutletTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
interface_table = tables.InterfaceTemplateTable(
|
||||
list(InterfaceTemplate.objects.restrict(request.user, 'view').filter(device_type=instance)),
|
||||
orderable=False
|
||||
)
|
||||
front_port_table = tables.FrontPortTemplateTable(
|
||||
FrontPortTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
rear_port_table = tables.RearPortTemplateTable(
|
||||
RearPortTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
devicebay_table = tables.DeviceBayTemplateTable(
|
||||
DeviceBayTemplate.objects.restrict(request.user, 'view').filter(device_type=instance),
|
||||
orderable=False
|
||||
)
|
||||
if request.user.has_perm('dcim.change_devicetype'):
|
||||
consoleport_table.columns.show('pk')
|
||||
consoleserverport_table.columns.show('pk')
|
||||
powerport_table.columns.show('pk')
|
||||
poweroutlet_table.columns.show('pk')
|
||||
interface_table.columns.show('pk')
|
||||
front_port_table.columns.show('pk')
|
||||
rear_port_table.columns.show('pk')
|
||||
devicebay_table.columns.show('pk')
|
||||
|
||||
return {
|
||||
'instance_count': instance_count,
|
||||
'consoleport_table': consoleport_table,
|
||||
'consoleserverport_table': consoleserverport_table,
|
||||
'powerport_table': powerport_table,
|
||||
'poweroutlet_table': poweroutlet_table,
|
||||
'interface_table': interface_table,
|
||||
'front_port_table': front_port_table,
|
||||
'rear_port_table': rear_port_table,
|
||||
'devicebay_table': devicebay_table,
|
||||
'active_tab': 'devicetype',
|
||||
}
|
||||
|
||||
|
||||
class DeviceTypeConsolePortsView(DeviceTypeComponentsView):
|
||||
model = ConsolePortTemplate
|
||||
table = tables.ConsolePortTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeConsoleServerPortsView(DeviceTypeComponentsView):
|
||||
model = ConsoleServerPortTemplate
|
||||
table = tables.ConsoleServerPortTemplateTable
|
||||
|
||||
|
||||
class DeviceTypePowerPortsView(DeviceTypeComponentsView):
|
||||
model = PowerPortTemplate
|
||||
table = tables.PowerPortTemplateTable
|
||||
|
||||
|
||||
class DeviceTypePowerOutletsView(DeviceTypeComponentsView):
|
||||
model = PowerOutletTemplate
|
||||
table = tables.PowerOutletTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeInterfacesView(DeviceTypeComponentsView):
|
||||
model = InterfaceTemplate
|
||||
table = tables.InterfaceTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeFrontPortsView(DeviceTypeComponentsView):
|
||||
model = FrontPortTemplate
|
||||
table = tables.FrontPortTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeRearPortsView(DeviceTypeComponentsView):
|
||||
model = RearPortTemplate
|
||||
table = tables.RearPortTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeDeviceBaysView(DeviceTypeComponentsView):
|
||||
model = DeviceBayTemplate
|
||||
table = tables.DeviceBayTemplateTable
|
||||
|
||||
|
||||
class DeviceTypeEditView(generic.ObjectEditView):
|
||||
queryset = DeviceType.objects.all()
|
||||
model_form = forms.DeviceTypeForm
|
||||
|
Reference in New Issue
Block a user