From dc68be5abf1deb9987f0a3b301d949dba6e0cf40 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 12 Jul 2017 16:42:45 -0400 Subject: [PATCH] Removed SearchTables; created DetailTables for models where needed --- netbox/circuits/tables.py | 29 ++-------- netbox/circuits/views.py | 2 +- netbox/dcim/tables.py | 90 ++++++++++------------------- netbox/dcim/views.py | 8 +-- netbox/ipam/tables.py | 114 +++++++++---------------------------- netbox/ipam/views.py | 24 ++++---- netbox/netbox/views.py | 42 +++++++------- netbox/secrets/tables.py | 10 +--- netbox/tenancy/tables.py | 10 +--- netbox/utilities/tables.py | 11 ---- 10 files changed, 106 insertions(+), 234 deletions(-) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index d09c5a7b2..58775b378 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import django_tables2 as tables from django_tables2.utils import Accessor -from utilities.tables import BaseTable, SearchTable, ToggleColumn +from utilities.tables import BaseTable, ToggleColumn from .models import Circuit, CircuitType, Provider @@ -21,19 +21,18 @@ CIRCUITTYPE_ACTIONS = """ class ProviderTable(BaseTable): pk = ToggleColumn() name = tables.LinkColumn() - circuit_count = tables.Column(accessor=Accessor('count_circuits'), verbose_name='Circuits') class Meta(BaseTable.Meta): model = Provider - fields = ('pk', 'name', 'asn', 'account', 'circuit_count') + fields = ('pk', 'name', 'asn', 'account',) -class ProviderSearchTable(SearchTable): - name = tables.LinkColumn() +class ProviderDetailTable(ProviderTable): + circuit_count = tables.Column(accessor=Accessor('count_circuits'), verbose_name='Circuits') - class Meta(SearchTable.Meta): + class Meta(ProviderTable.Meta): model = Provider - fields = ('name', 'asn', 'account') + fields = ('pk', 'name', 'asn', 'account', 'circuit_count') # @@ -74,19 +73,3 @@ class CircuitTable(BaseTable): class Meta(BaseTable.Meta): model = Circuit fields = ('pk', 'cid', 'type', 'provider', 'tenant', 'a_side', 'z_side', 'description') - - -class CircuitSearchTable(SearchTable): - cid = tables.LinkColumn(verbose_name='ID') - provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')]) - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - a_side = tables.LinkColumn( - 'dcim:site', accessor=Accessor('termination_a.site'), args=[Accessor('termination_a.site.slug')] - ) - z_side = tables.LinkColumn( - 'dcim:site', accessor=Accessor('termination_z.site'), args=[Accessor('termination_z.site.slug')] - ) - - class Meta(SearchTable.Meta): - model = Circuit - fields = ('cid', 'type', 'provider', 'tenant', 'a_side', 'z_side', 'description') diff --git a/netbox/circuits/views.py b/netbox/circuits/views.py index eda37340d..cb9e95669 100644 --- a/netbox/circuits/views.py +++ b/netbox/circuits/views.py @@ -26,7 +26,7 @@ class ProviderListView(ObjectListView): queryset = Provider.objects.annotate(count_circuits=Count('circuits')) filter = filters.ProviderFilter filter_form = forms.ProviderFilterForm - table = tables.ProviderTable + table = tables.ProviderDetailTable template_name = 'circuits/provider_list.html' diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py index 626bc9e7a..30fe83c9f 100644 --- a/netbox/dcim/tables.py +++ b/netbox/dcim/tables.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import django_tables2 as tables from django_tables2.utils import Accessor -from utilities.tables import BaseTable, SearchTable, ToggleColumn +from utilities.tables import BaseTable, ToggleColumn from .models import ( ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, Manufacturer, Platform, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, @@ -142,30 +142,26 @@ class SiteTable(BaseTable): name = tables.LinkColumn() region = tables.TemplateColumn(template_code=SITE_REGION_LINK) tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) + + class Meta(BaseTable.Meta): + model = Site + fields = ('pk', 'name', 'facility', 'region', 'tenant', 'asn') + + +class SiteDetailTable(SiteTable): rack_count = tables.Column(accessor=Accessor('count_racks'), orderable=False, verbose_name='Racks') device_count = tables.Column(accessor=Accessor('count_devices'), orderable=False, verbose_name='Devices') prefix_count = tables.Column(accessor=Accessor('count_prefixes'), orderable=False, verbose_name='Prefixes') vlan_count = tables.Column(accessor=Accessor('count_vlans'), orderable=False, verbose_name='VLANs') circuit_count = tables.Column(accessor=Accessor('count_circuits'), orderable=False, verbose_name='Circuits') - class Meta(BaseTable.Meta): - model = Site + class Meta(SiteTable.Meta): fields = ( 'pk', 'name', 'facility', 'region', 'tenant', 'asn', 'rack_count', 'device_count', 'prefix_count', 'vlan_count', 'circuit_count', ) -class SiteSearchTable(SearchTable): - name = tables.LinkColumn() - region = tables.TemplateColumn(template_code=SITE_REGION_LINK) - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - - class Meta(SearchTable.Meta): - model = Site - fields = ('name', 'facility', 'region', 'tenant', 'asn') - - # # Rack groups # @@ -214,29 +210,22 @@ class RackTable(BaseTable): tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) role = tables.TemplateColumn(RACK_ROLE) u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height') - devices = tables.Column(accessor=Accessor('device_count')) - get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') class Meta(BaseTable.Meta): model = Rack + fields = ('pk', 'name', 'site', 'group', 'facility_id', 'tenant', 'role', 'u_height') + + +class RackDetailTable(RackTable): + devices = tables.Column(accessor=Accessor('device_count')) + get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') + + class Meta(RackTable.Meta): fields = ( 'pk', 'name', 'site', 'group', 'facility_id', 'tenant', 'role', 'u_height', 'devices', 'get_utilization' ) -class RackSearchTable(SearchTable): - name = tables.LinkColumn() - site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) - group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group') - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - role = tables.TemplateColumn(RACK_ROLE) - u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height') - - class Meta(SearchTable.Meta): - model = Rack - fields = ('name', 'site', 'group', 'facility_id', 'tenant', 'role', 'u_height') - - class RackImportTable(BaseTable): name = tables.LinkColumn('dcim:rack', args=[Accessor('pk')], verbose_name='Name') site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site') @@ -296,29 +285,22 @@ class DeviceTypeTable(BaseTable): is_pdu = tables.BooleanColumn(verbose_name='PDU') is_network_device = tables.BooleanColumn(verbose_name='Net') subdevice_role = tables.TemplateColumn(SUBDEVICE_ROLE_TEMPLATE, verbose_name='Subdevice Role') - instance_count = tables.Column(verbose_name='Instances') class Meta(BaseTable.Meta): model = DeviceType fields = ( 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu', - 'is_network_device', 'subdevice_role', 'instance_count' + 'is_network_device', 'subdevice_role', ) -class DeviceTypeSearchTable(SearchTable): - model = tables.LinkColumn('dcim:devicetype', args=[Accessor('pk')], verbose_name='Device Type') - is_full_depth = tables.BooleanColumn(verbose_name='Full Depth') - is_console_server = tables.BooleanColumn(verbose_name='CS') - is_pdu = tables.BooleanColumn(verbose_name='PDU') - is_network_device = tables.BooleanColumn(verbose_name='Net') - subdevice_role = tables.TemplateColumn(SUBDEVICE_ROLE_TEMPLATE, verbose_name='Subdevice Role') +class DeviceTypeDetailTable(DeviceTypeTable): + instance_count = tables.Column(verbose_name='Instances') - class Meta(SearchTable.Meta): - model = DeviceType + class Meta(DeviceTypeTable.Meta): fields = ( - 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu', - 'is_network_device', 'subdevice_role', + 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu', + 'is_network_device', 'subdevice_role', 'instance_count', ) @@ -439,32 +421,22 @@ class DeviceTable(BaseTable): 'dcim:devicetype', args=[Accessor('device_type.pk')], verbose_name='Type', text=lambda record: record.device_type.full_name ) + + class Meta(BaseTable.Meta): + model = Device + fields = ('pk', 'name', 'status', 'tenant', 'site', 'rack', 'device_role', 'device_type') + + +class DeviceDetailTable(DeviceTable): primary_ip = tables.TemplateColumn( orderable=False, verbose_name='IP Address', template_code=DEVICE_PRIMARY_IP ) - class Meta(BaseTable.Meta): + class Meta(DeviceTable.Meta): model = Device fields = ('pk', 'name', 'status', 'tenant', 'site', 'rack', 'device_role', 'device_type', 'primary_ip') -class DeviceSearchTable(SearchTable): - name = tables.TemplateColumn(template_code=DEVICE_LINK) - status = tables.TemplateColumn(template_code=DEVICE_STATUS, verbose_name='Status') - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) - rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')]) - device_role = tables.TemplateColumn(DEVICE_ROLE, verbose_name='Role') - device_type = tables.LinkColumn( - 'dcim:devicetype', args=[Accessor('device_type.pk')], verbose_name='Type', - text=lambda record: record.device_type.full_name - ) - - class Meta(SearchTable.Meta): - model = Device - fields = ('name', 'status', 'tenant', 'site', 'rack', 'device_role', 'device_type') - - class DeviceImportTable(BaseTable): name = tables.TemplateColumn(template_code=DEVICE_LINK, verbose_name='Name') status = tables.TemplateColumn(template_code=DEVICE_STATUS, verbose_name='Status') diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index c257129a7..37ed69678 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -216,7 +216,7 @@ class SiteListView(ObjectListView): queryset = Site.objects.select_related('region', 'tenant') filter = filters.SiteFilter filter_form = forms.SiteFilterForm - table = tables.SiteTable + table = tables.SiteDetailTable template_name = 'dcim/site_list.html' @@ -354,7 +354,7 @@ class RackListView(ObjectListView): ) filter = filters.RackFilter filter_form = forms.RackFilterForm - table = tables.RackTable + table = tables.RackDetailTable template_name = 'dcim/rack_list.html' @@ -550,7 +550,7 @@ class DeviceTypeListView(ObjectListView): queryset = DeviceType.objects.select_related('manufacturer').annotate(instance_count=Count('instances')) filter = filters.DeviceTypeFilter filter_form = forms.DeviceTypeFilterForm - table = tables.DeviceTypeTable + table = tables.DeviceTypeDetailTable template_name = 'dcim/devicetype_list.html' @@ -805,7 +805,7 @@ class DeviceListView(ObjectListView): 'primary_ip4', 'primary_ip6') filter = filters.DeviceFilter filter_form = forms.DeviceFilterForm - table = tables.DeviceTable + table = tables.DeviceDetailTable template_name = 'dcim/device_list.html' diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index b648eb9c9..8753d5f94 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import django_tables2 as tables from django_tables2.utils import Accessor -from utilities.tables import BaseTable, SearchTable, ToggleColumn +from utilities.tables import BaseTable, ToggleColumn from .models import Aggregate, IPAddress, Prefix, RIR, Role, VLAN, VLANGroup, VRF @@ -152,16 +152,6 @@ class VRFTable(BaseTable): fields = ('pk', 'name', 'rd', 'tenant', 'description') -class VRFSearchTable(SearchTable): - name = tables.LinkColumn() - rd = tables.Column(verbose_name='RD') - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - - class Meta(SearchTable.Meta): - model = VRF - fields = ('name', 'rd', 'tenant', 'description') - - # # RIRs # @@ -197,24 +187,21 @@ class RIRTable(BaseTable): class AggregateTable(BaseTable): pk = ToggleColumn() prefix = tables.LinkColumn(verbose_name='Aggregate') - child_count = tables.Column(verbose_name='Prefixes') - get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') date_added = tables.DateColumn(format="Y-m-d", verbose_name='Added') class Meta(BaseTable.Meta): model = Aggregate + fields = ('pk', 'prefix', 'rir', 'date_added', 'description') + + +class AggregateDetailTable(AggregateTable): + child_count = tables.Column(verbose_name='Prefixes') + get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') + + class Meta(AggregateTable.Meta): fields = ('pk', 'prefix', 'rir', 'child_count', 'get_utilization', 'date_added', 'description') -class AggregateSearchTable(SearchTable): - prefix = tables.LinkColumn(verbose_name='Aggregate') - date_added = tables.DateColumn(format="Y-m-d", verbose_name='Added') - - class Meta(SearchTable.Meta): - model = Aggregate - fields = ('prefix', 'rir', 'date_added', 'description') - - # # Roles # @@ -241,7 +228,6 @@ class PrefixTable(BaseTable): prefix = tables.TemplateColumn(PREFIX_LINK, attrs={'th': {'style': 'padding-left: 17px'}}) status = tables.TemplateColumn(STATUS_LABEL) vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF') - get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') tenant = tables.TemplateColumn(TENANT_LINK) site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) vlan = tables.LinkColumn('ipam:vlan', args=[Accessor('vlan.pk')], verbose_name='VLAN') @@ -249,37 +235,17 @@ class PrefixTable(BaseTable): class Meta(BaseTable.Meta): model = Prefix - fields = ('pk', 'prefix', 'status', 'vrf', 'get_utilization', 'tenant', 'site', 'vlan', 'role', 'description') + fields = ('pk', 'prefix', 'status', 'vrf', 'tenant', 'site', 'vlan', 'role', 'description') row_attrs = { 'class': lambda record: 'success' if not record.pk else '', } -class PrefixBriefTable(BaseTable): - prefix = tables.TemplateColumn(PREFIX_LINK_BRIEF) - vrf = tables.LinkColumn('ipam:vrf', args=[Accessor('vrf.pk')], default='Global') - site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) - status = tables.TemplateColumn(STATUS_LABEL) - vlan = tables.LinkColumn('ipam:vlan', args=[Accessor('vlan.pk')]) +class PrefixDetailTable(PrefixTable): + get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') - class Meta(BaseTable.Meta): - model = Prefix - fields = ('prefix', 'vrf', 'status', 'site', 'vlan', 'role') - orderable = False - - -class PrefixSearchTable(SearchTable): - prefix = tables.TemplateColumn(PREFIX_LINK, attrs={'th': {'style': 'padding-left: 17px'}}) - status = tables.TemplateColumn(STATUS_LABEL) - vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF') - tenant = tables.TemplateColumn(TENANT_LINK) - site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) - vlan = tables.LinkColumn('ipam:vlan', args=[Accessor('vlan.pk')], verbose_name='VLAN') - role = tables.TemplateColumn(PREFIX_ROLE_LINK) - - class Meta(SearchTable.Meta): - model = Prefix - fields = ('prefix', 'status', 'vrf', 'tenant', 'site', 'vlan', 'role', 'description') + class Meta(PrefixTable.Meta): + fields = ('pk', 'prefix', 'status', 'vrf', 'get_utilization', 'tenant', 'site', 'vlan', 'role', 'description') # @@ -292,43 +258,26 @@ class IPAddressTable(BaseTable): status = tables.TemplateColumn(STATUS_LABEL) vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF') tenant = tables.TemplateColumn(TENANT_LINK) - nat_inside = tables.LinkColumn( - 'ipam:ipaddress', args=[Accessor('nat_inside.pk')], orderable=False, verbose_name='NAT (Inside)' - ) device = tables.TemplateColumn(IPADDRESS_DEVICE, orderable=False) + interface = tables.Column(orderable=False) class Meta(BaseTable.Meta): model = IPAddress - fields = ('pk', 'address', 'vrf', 'status', 'role', 'tenant', 'nat_inside', 'device', 'description') + fields = ('pk', 'address', 'vrf', 'status', 'role', 'tenant', 'device', 'interface', 'description') row_attrs = { 'class': lambda record: 'success' if not isinstance(record, IPAddress) else '', } -class IPAddressBriefTable(BaseTable): - address = tables.LinkColumn('ipam:ipaddress', args=[Accessor('pk')], verbose_name='IP Address') - device = tables.LinkColumn('dcim:device', args=[Accessor('interface.device.pk')], orderable=False) - interface = tables.Column(orderable=False) +class IPAddressDetailTable(IPAddressTable): nat_inside = tables.LinkColumn( 'ipam:ipaddress', args=[Accessor('nat_inside.pk')], orderable=False, verbose_name='NAT (Inside)' ) - class Meta(BaseTable.Meta): - model = IPAddress - fields = ('address', 'device', 'interface', 'nat_inside') - - -class IPAddressSearchTable(SearchTable): - address = tables.TemplateColumn(IPADDRESS_LINK, verbose_name='IP Address') - status = tables.TemplateColumn(STATUS_LABEL) - vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF') - tenant = tables.TemplateColumn(TENANT_LINK) - device = tables.LinkColumn('dcim:device', args=[Accessor('interface.device.pk')], orderable=False) - interface = tables.Column(orderable=False) - - class Meta(SearchTable.Meta): - model = IPAddress - fields = ('address', 'vrf', 'status', 'role', 'tenant', 'device', 'interface', 'description') + class Meta(IPAddressTable.Meta): + fields = ( + 'pk', 'address', 'vrf', 'status', 'role', 'tenant', 'nat_inside', 'device', 'interface', 'description', + ) # @@ -358,24 +307,17 @@ class VLANTable(BaseTable): vid = tables.LinkColumn('ipam:vlan', args=[Accessor('pk')], verbose_name='ID') site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group') - prefixes = tables.TemplateColumn(VLAN_PREFIXES, orderable=False, verbose_name='Prefixes') tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) status = tables.TemplateColumn(STATUS_LABEL) role = tables.TemplateColumn(VLAN_ROLE_LINK) class Meta(BaseTable.Meta): model = VLAN + fields = ('pk', 'vid', 'site', 'group', 'name', 'tenant', 'status', 'role', 'description') + + +class VLANDetailTable(VLANTable): + prefixes = tables.TemplateColumn(VLAN_PREFIXES, orderable=False, verbose_name='Prefixes') + + class Meta(VLANTable.Meta): fields = ('pk', 'vid', 'site', 'group', 'name', 'prefixes', 'tenant', 'status', 'role', 'description') - - -class VLANSearchTable(SearchTable): - vid = tables.LinkColumn('ipam:vlan', args=[Accessor('pk')], verbose_name='ID') - site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')]) - group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group') - tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')]) - status = tables.TemplateColumn(STATUS_LABEL) - role = tables.TemplateColumn(VLAN_ROLE_LINK) - - class Meta(SearchTable.Meta): - model = VLAN - fields = ('vid', 'site', 'group', 'name', 'tenant', 'status', 'role', 'description') diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 74432d180..74f7ed9c2 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -103,8 +103,8 @@ class VRFView(View): def get(self, request, pk): vrf = get_object_or_404(VRF.objects.all(), pk=pk) - prefix_table = tables.PrefixBriefTable( - list(Prefix.objects.filter(vrf=vrf).select_related('site', 'role')) + prefix_table = tables.PrefixTable( + list(Prefix.objects.filter(vrf=vrf).select_related('site', 'role')), orderable=False ) prefix_table.exclude = ('vrf',) @@ -273,7 +273,7 @@ class AggregateListView(ObjectListView): }) filter = filters.AggregateFilter filter_form = forms.AggregateFilterForm - table = tables.AggregateTable + table = tables.AggregateDetailTable template_name = 'ipam/aggregate_list.html' def extra_context(self): @@ -410,7 +410,7 @@ class PrefixListView(ObjectListView): queryset = Prefix.objects.select_related('site', 'vrf__tenant', 'tenant', 'vlan', 'role') filter = filters.PrefixFilter filter_form = forms.PrefixFilterForm - table = tables.PrefixTable + table = tables.PrefixDetailTable template_name = 'ipam/prefix_list.html' def alter_queryset(self, request): @@ -445,7 +445,7 @@ class PrefixView(View): ).select_related( 'site', 'role' ).annotate_depth() - parent_prefix_table = tables.PrefixBriefTable(parent_prefixes) + parent_prefix_table = tables.PrefixTable(list(parent_prefixes), orderable=False) parent_prefix_table.exclude = ('vrf',) # Duplicate prefixes table @@ -456,7 +456,7 @@ class PrefixView(View): ).select_related( 'site', 'role' ) - duplicate_prefix_table = tables.PrefixBriefTable(list(duplicate_prefixes)) + duplicate_prefix_table = tables.PrefixTable(list(duplicate_prefixes), orderable=False) duplicate_prefix_table.exclude = ('vrf',) # Child prefixes table @@ -585,7 +585,7 @@ class IPAddressListView(ObjectListView): queryset = IPAddress.objects.select_related('vrf__tenant', 'tenant', 'interface__device', 'nat_inside') filter = filters.IPAddressFilter filter_form = forms.IPAddressFilterForm - table = tables.IPAddressTable + table = tables.IPAddressDetailTable template_name = 'ipam/ipaddress_list.html' @@ -601,7 +601,7 @@ class IPAddressView(View): ).select_related( 'site', 'role' ) - parent_prefixes_table = tables.PrefixBriefTable(list(parent_prefixes)) + parent_prefixes_table = tables.PrefixTable(list(parent_prefixes), orderable=False) parent_prefixes_table.exclude = ('vrf',) # Duplicate IPs table @@ -612,7 +612,7 @@ class IPAddressView(View): ).select_related( 'interface__device', 'nat_inside' ) - duplicate_ips_table = tables.IPAddressBriefTable(list(duplicate_ips)) + duplicate_ips_table = tables.IPAddressTable(list(duplicate_ips), orderable=False) # Related IP table related_ips = IPAddress.objects.select_related( @@ -622,7 +622,7 @@ class IPAddressView(View): ).filter( vrf=ipaddress.vrf, address__net_contained_or_equal=str(ipaddress.address) ) - related_ips_table = tables.IPAddressBriefTable(list(related_ips)) + related_ips_table = tables.IPAddressTable(list(related_ips), orderable=False) return render(request, 'ipam/ipaddress.html', { 'ipaddress': ipaddress, @@ -722,7 +722,7 @@ class VLANListView(ObjectListView): queryset = VLAN.objects.select_related('site', 'group', 'tenant', 'role').prefetch_related('prefixes') filter = filters.VLANFilter filter_form = forms.VLANFilterForm - table = tables.VLANTable + table = tables.VLANDetailTable template_name = 'ipam/vlan_list.html' @@ -734,7 +734,7 @@ class VLANView(View): 'site__region', 'tenant__group', 'role' ), pk=pk) prefixes = Prefix.objects.filter(vlan=vlan).select_related('vrf', 'site', 'role') - prefix_table = tables.PrefixBriefTable(list(prefixes)) + prefix_table = tables.PrefixTable(list(prefixes), orderable=False) prefix_table.exclude = ('vlan',) return render(request, 'ipam/vlan.html', { diff --git a/netbox/netbox/views.py b/netbox/netbox/views.py index 6f642063b..d5224b462 100644 --- a/netbox/netbox/views.py +++ b/netbox/netbox/views.py @@ -11,20 +11,20 @@ from django.views.generic import View from circuits.filters import CircuitFilter, ProviderFilter from circuits.models import Circuit, Provider -from circuits.tables import CircuitSearchTable, ProviderSearchTable +from circuits.tables import CircuitTable, ProviderTable from dcim.filters import DeviceFilter, DeviceTypeFilter, RackFilter, SiteFilter from dcim.models import ConsolePort, Device, DeviceType, InterfaceConnection, PowerPort, Rack, Site -from dcim.tables import DeviceSearchTable, DeviceTypeSearchTable, RackSearchTable, SiteSearchTable +from dcim.tables import DeviceTable, DeviceTypeTable, RackTable, SiteTable from extras.models import TopologyMap, UserAction from ipam.filters import AggregateFilter, IPAddressFilter, PrefixFilter, VLANFilter, VRFFilter from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF -from ipam.tables import AggregateSearchTable, IPAddressSearchTable, PrefixSearchTable, VLANSearchTable, VRFSearchTable +from ipam.tables import AggregateTable, IPAddressTable, PrefixTable, VLANTable, VRFTable from secrets.filters import SecretFilter from secrets.models import Secret -from secrets.tables import SecretSearchTable +from secrets.tables import SecretTable from tenancy.filters import TenantFilter from tenancy.models import Tenant -from tenancy.tables import TenantSearchTable +from tenancy.tables import TenantTable from .forms import SearchForm @@ -34,83 +34,85 @@ SEARCH_TYPES = OrderedDict(( ('provider', { 'queryset': Provider.objects.all(), 'filter': ProviderFilter, - 'table': ProviderSearchTable, + 'table': ProviderTable, 'url': 'circuits:provider_list', }), ('circuit', { 'queryset': Circuit.objects.select_related('type', 'provider', 'tenant').prefetch_related('terminations__site'), 'filter': CircuitFilter, - 'table': CircuitSearchTable, + 'table': CircuitTable, 'url': 'circuits:circuit_list', }), # DCIM ('site', { 'queryset': Site.objects.select_related('region', 'tenant'), 'filter': SiteFilter, - 'table': SiteSearchTable, + 'table': SiteTable, 'url': 'dcim:site_list', }), ('rack', { 'queryset': Rack.objects.select_related('site', 'group', 'tenant', 'role'), 'filter': RackFilter, - 'table': RackSearchTable, + 'table': RackTable, 'url': 'dcim:rack_list', }), ('devicetype', { 'queryset': DeviceType.objects.select_related('manufacturer'), 'filter': DeviceTypeFilter, - 'table': DeviceTypeSearchTable, + 'table': DeviceTypeTable, 'url': 'dcim:devicetype_list', }), ('device', { - 'queryset': Device.objects.select_related('device_type__manufacturer', 'device_role', 'tenant', 'site', 'rack'), + 'queryset': Device.objects.select_related( + 'device_type__manufacturer', 'device_role', 'tenant', 'site', 'rack' + ), 'filter': DeviceFilter, - 'table': DeviceSearchTable, + 'table': DeviceTable, 'url': 'dcim:device_list', }), # IPAM ('vrf', { 'queryset': VRF.objects.select_related('tenant'), 'filter': VRFFilter, - 'table': VRFSearchTable, + 'table': VRFTable, 'url': 'ipam:vrf_list', }), ('aggregate', { 'queryset': Aggregate.objects.select_related('rir'), 'filter': AggregateFilter, - 'table': AggregateSearchTable, + 'table': AggregateTable, 'url': 'ipam:aggregate_list', }), ('prefix', { 'queryset': Prefix.objects.select_related('site', 'vrf__tenant', 'tenant', 'vlan', 'role'), 'filter': PrefixFilter, - 'table': PrefixSearchTable, + 'table': PrefixTable, 'url': 'ipam:prefix_list', }), ('ipaddress', { 'queryset': IPAddress.objects.select_related('vrf__tenant', 'tenant', 'interface__device'), 'filter': IPAddressFilter, - 'table': IPAddressSearchTable, + 'table': IPAddressTable, 'url': 'ipam:ipaddress_list', }), ('vlan', { 'queryset': VLAN.objects.select_related('site', 'group', 'tenant', 'role'), 'filter': VLANFilter, - 'table': VLANSearchTable, + 'table': VLANTable, 'url': 'ipam:vlan_list', }), # Secrets ('secret', { 'queryset': Secret.objects.select_related('role', 'device'), 'filter': SecretFilter, - 'table': SecretSearchTable, + 'table': SecretTable, 'url': 'secrets:secret_list', }), # Tenancy ('tenant', { 'queryset': Tenant.objects.select_related('group'), 'filter': TenantFilter, - 'table': TenantSearchTable, + 'table': TenantTable, 'url': 'tenancy:tenant_list', }), )) @@ -189,7 +191,7 @@ class SearchView(View): # Construct the results table for this object type filtered_queryset = filter_cls({'q': form.cleaned_data['q']}, queryset=queryset).qs - table = table(filtered_queryset) + table = table(filtered_queryset, orderable=False) table.paginate(per_page=SEARCH_MAX_RESULTS) if table.page: diff --git a/netbox/secrets/tables.py b/netbox/secrets/tables.py index 980c093b7..30424b0bb 100644 --- a/netbox/secrets/tables.py +++ b/netbox/secrets/tables.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import django_tables2 as tables -from utilities.tables import BaseTable, SearchTable, ToggleColumn +from utilities.tables import BaseTable, ToggleColumn from .models import SecretRole, Secret @@ -43,11 +43,3 @@ class SecretTable(BaseTable): class Meta(BaseTable.Meta): model = Secret fields = ('pk', 'device', 'role', 'name', 'last_updated') - - -class SecretSearchTable(SearchTable): - device = tables.LinkColumn() - - class Meta(SearchTable.Meta): - model = Secret - fields = ('device', 'role', 'name', 'last_updated') diff --git a/netbox/tenancy/tables.py b/netbox/tenancy/tables.py index 9941e269a..4ef774fb6 100644 --- a/netbox/tenancy/tables.py +++ b/netbox/tenancy/tables.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import django_tables2 as tables -from utilities.tables import BaseTable, SearchTable, ToggleColumn +from utilities.tables import BaseTable, ToggleColumn from .models import Tenant, TenantGroup @@ -43,11 +43,3 @@ class TenantTable(BaseTable): class Meta(BaseTable.Meta): model = Tenant fields = ('pk', 'name', 'group', 'description') - - -class TenantSearchTable(SearchTable): - name = tables.LinkColumn() - - class Meta(SearchTable.Meta): - model = Tenant - fields = ('name', 'group', 'description') diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index 1dd8969a1..579280b64 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -16,21 +16,10 @@ class BaseTable(tables.Table): if self.empty_text is None: self.empty_text = 'No {} found.'.format(self._meta.model._meta.verbose_name_plural) - class Meta: - attrs = { - 'class': 'table table-hover', - } - - -class SearchTable(tables.Table): - """ - Default table for search results - """ class Meta: attrs = { 'class': 'table table-hover table-headings', } - orderable = False class ToggleColumn(tables.CheckBoxColumn):