From 7e18b0dd3a2df8c9d51aaf97b2b0b47585863d0a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 9 Jun 2021 15:52:49 -0400 Subject: [PATCH] Remove csv_headers model attributes --- netbox/circuits/forms.py | 6 ++- netbox/circuits/models.py | 12 ----- netbox/dcim/forms.py | 61 ++++++++++++++++--------- netbox/dcim/models/cables.py | 5 -- netbox/dcim/models/device_components.py | 27 ----------- netbox/dcim/models/devices.py | 12 ----- netbox/dcim/models/power.py | 6 --- netbox/dcim/models/racks.py | 8 ---- netbox/dcim/models/sites.py | 10 ---- netbox/dcim/tests/test_views.py | 9 +++- netbox/extras/forms.py | 2 +- netbox/extras/models/change_logging.py | 5 -- netbox/extras/models/tags.py | 2 - netbox/ipam/forms.py | 21 +++++---- netbox/ipam/models/ip.py | 13 ------ netbox/ipam/models/services.py | 2 - netbox/ipam/models/vlans.py | 3 -- netbox/ipam/models/vrfs.py | 3 -- netbox/tenancy/forms.py | 4 +- netbox/tenancy/models.py | 3 -- netbox/utilities/testing/views.py | 7 ++- netbox/virtualization/forms.py | 14 ++++-- netbox/virtualization/models.py | 12 ----- 23 files changed, 78 insertions(+), 169 deletions(-) diff --git a/netbox/circuits/forms.py b/netbox/circuits/forms.py index 5b8b6f1b8..da399453b 100644 --- a/netbox/circuits/forms.py +++ b/netbox/circuits/forms.py @@ -60,7 +60,9 @@ class ProviderCSVForm(CustomFieldModelCSVForm): class Meta: model = Provider - fields = Provider.csv_headers + fields = ( + 'name', 'slug', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'comments', + ) class ProviderBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -234,7 +236,7 @@ class CircuitTypeCSVForm(CustomFieldModelCSVForm): class Meta: model = CircuitType - fields = CircuitType.csv_headers + fields = ('name', 'slug', 'description') help_texts = { 'name': 'Name of circuit type', } diff --git a/netbox/circuits/models.py b/netbox/circuits/models.py index a40455a47..39f38d0b0 100644 --- a/netbox/circuits/models.py +++ b/netbox/circuits/models.py @@ -63,9 +63,6 @@ class Provider(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'name', 'slug', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'comments', - ] clone_fields = [ 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', ] @@ -106,10 +103,6 @@ class ProviderNetwork(PrimaryModel): blank=True ) - csv_headers = [ - 'provider', 'name', 'description', 'comments', - ] - objects = RestrictedQuerySet.as_manager() class Meta: @@ -150,8 +143,6 @@ class CircuitType(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'description'] - class Meta: ordering = ['name'] @@ -232,9 +223,6 @@ class Circuit(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'cid', 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', 'comments', - ] clone_fields = [ 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', ] diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index d6c119eca..ea0d7eeac 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -209,7 +209,7 @@ class RegionCSVForm(CustomFieldModelCSVForm): class Meta: model = Region - fields = Region.csv_headers + fields = ('name', 'slug', 'parent', 'description') class RegionBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -262,7 +262,7 @@ class SiteGroupCSVForm(CustomFieldModelCSVForm): class Meta: model = SiteGroup - fields = SiteGroup.csv_headers + fields = ('name', 'slug', 'parent', 'description') class SiteGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -383,7 +383,11 @@ class SiteCSVForm(CustomFieldModelCSVForm): class Meta: model = Site - fields = Site.csv_headers + fields = ( + 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', + 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', + 'contact_email', 'comments', + ) help_texts = { 'time_zone': mark_safe( 'Time zone (available options)' @@ -522,7 +526,7 @@ class LocationCSVForm(CustomFieldModelCSVForm): class Meta: model = Location - fields = Location.csv_headers + fields = ('site', 'parent', 'name', 'slug', 'description') class LocationBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -595,7 +599,7 @@ class RackRoleCSVForm(CustomFieldModelCSVForm): class Meta: model = RackRole - fields = RackRole.csv_headers + fields = ('name', 'slug', 'color', 'description') help_texts = { 'color': mark_safe('RGB color in hexadecimal (e.g. 00ff00)'), } @@ -728,7 +732,10 @@ class RackCSVForm(CustomFieldModelCSVForm): class Meta: model = Rack - fields = Rack.csv_headers + fields = ( + 'site', 'location', 'name', 'facility_id', 'tenant', 'status', 'role', 'type', 'serial', 'asset_tag', + 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'comments', + ) def __init__(self, data=None, *args, **kwargs): super().__init__(data, *args, **kwargs) @@ -1114,7 +1121,7 @@ class ManufacturerCSVForm(CustomFieldModelCSVForm): class Meta: model = Manufacturer - fields = Manufacturer.csv_headers + fields = ('name', 'slug', 'description') class ManufacturerBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -1923,7 +1930,7 @@ class DeviceRoleCSVForm(CustomFieldModelCSVForm): class Meta: model = DeviceRole - fields = DeviceRole.csv_headers + fields = ('name', 'slug', 'color', 'vm_role', 'description') help_texts = { 'color': mark_safe('RGB color in hexadecimal (e.g. 00ff00)'), } @@ -1987,7 +1994,7 @@ class PlatformCSVForm(CustomFieldModelCSVForm): class Meta: model = Platform - fields = Platform.csv_headers + fields = ('name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description') class PlatformBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -2676,7 +2683,7 @@ class ConsolePortCSVForm(CustomFieldModelCSVForm): class Meta: model = ConsolePort - fields = ConsolePort.csv_headers + fields = ('device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description') # @@ -2783,7 +2790,7 @@ class ConsoleServerPortCSVForm(CustomFieldModelCSVForm): class Meta: model = ConsoleServerPort - fields = ConsoleServerPort.csv_headers + fields = ('device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description') # @@ -2886,7 +2893,9 @@ class PowerPortCSVForm(CustomFieldModelCSVForm): class Meta: model = PowerPort - fields = PowerPort.csv_headers + fields = ( + 'device', 'name', 'label', 'type', 'mark_connected', 'maximum_draw', 'allocated_draw', 'description', + ) # @@ -3036,7 +3045,7 @@ class PowerOutletCSVForm(CustomFieldModelCSVForm): class Meta: model = PowerOutlet - fields = PowerOutlet.csv_headers + fields = ('device', 'name', 'label', 'type', 'mark_connected', 'power_port', 'feed_leg', 'description') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -3376,7 +3385,10 @@ class InterfaceCSVForm(CustomFieldModelCSVForm): class Meta: model = Interface - fields = Interface.csv_headers + fields = ( + 'device', 'name', 'label', 'parent', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address', 'mtu', + 'mgmt_only', 'description', 'mode', + ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -3559,7 +3571,9 @@ class FrontPortCSVForm(CustomFieldModelCSVForm): class Meta: model = FrontPort - fields = FrontPort.csv_headers + fields = ( + 'device', 'name', 'label', 'type', 'mark_connected', 'rear_port', 'rear_port_position', 'description', + ) help_texts = { 'rear_port_position': 'Mapped position on corresponding rear port', } @@ -3675,7 +3689,7 @@ class RearPortCSVForm(CustomFieldModelCSVForm): class Meta: model = RearPort - fields = RearPort.csv_headers + fields = ('device', 'name', 'label', 'type', 'mark_connected', 'positions', 'description') help_texts = { 'positions': 'Number of front ports which may be mapped' } @@ -3774,7 +3788,7 @@ class DeviceBayCSVForm(CustomFieldModelCSVForm): class Meta: model = DeviceBay - fields = DeviceBay.csv_headers + fields = ('device', 'name', 'label', 'installed_device', 'description') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -3880,7 +3894,9 @@ class InventoryItemCSVForm(CustomFieldModelCSVForm): class Meta: model = InventoryItem - fields = InventoryItem.csv_headers + fields = ( + 'device', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered', 'description', + ) class InventoryItemBulkCreateForm( @@ -4763,7 +4779,7 @@ class VirtualChassisCSVForm(CustomFieldModelCSVForm): class Meta: model = VirtualChassis - fields = VirtualChassis.csv_headers + fields = ('name', 'domain', 'master') class VirtualChassisFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm): @@ -4857,7 +4873,7 @@ class PowerPanelCSVForm(CustomFieldModelCSVForm): class Meta: model = PowerPanel - fields = PowerPanel.csv_headers + fields = ('site', 'location', 'name') def __init__(self, data=None, *args, **kwargs): super().__init__(data, *args, **kwargs) @@ -5054,7 +5070,10 @@ class PowerFeedCSVForm(CustomFieldModelCSVForm): class Meta: model = PowerFeed - fields = PowerFeed.csv_headers + fields = ( + 'site', 'power_panel', 'location', 'rack', 'name', 'status', 'type', 'mark_connected', 'supply', 'phase', + 'voltage', 'amperage', 'max_utilization', 'comments', + ) def __init__(self, data=None, *args, **kwargs): super().__init__(data, *args, **kwargs) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 302623cb0..c3f8cac3f 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -111,11 +111,6 @@ class Cable(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'termination_a_type', 'termination_a_id', 'termination_b_type', 'termination_b_id', 'type', 'status', 'label', - 'color', 'length', 'length_unit', - ] - class Meta: ordering = ['pk'] unique_together = ( diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index c58eb5cc9..1729fdaa4 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -229,8 +229,6 @@ class ConsolePort(ComponentModel, CableTermination, PathEndpoint): help_text='Port speed in bits per second' ) - csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description'] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -261,8 +259,6 @@ class ConsoleServerPort(ComponentModel, CableTermination, PathEndpoint): help_text='Port speed in bits per second' ) - csv_headers = ['device', 'name', 'label', 'type', 'speed', 'mark_connected', 'description'] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -299,10 +295,6 @@ class PowerPort(ComponentModel, CableTermination, PathEndpoint): help_text="Allocated power draw (watts)" ) - csv_headers = [ - 'device', 'name', 'label', 'type', 'mark_connected', 'maximum_draw', 'allocated_draw', 'description', - ] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -399,8 +391,6 @@ class PowerOutlet(ComponentModel, CableTermination, PathEndpoint): help_text="Phase (for three-phase feeds)" ) - csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'power_port', 'feed_leg', 'description'] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -524,11 +514,6 @@ class Interface(ComponentModel, BaseInterface, CableTermination, PathEndpoint): related_query_name='interface' ) - csv_headers = [ - 'device', 'name', 'label', 'parent', 'lag', 'type', 'enabled', 'mark_connected', 'mac_address', 'mtu', - 'mgmt_only', 'description', 'mode', - ] - class Meta: ordering = ('device', CollateAsChar('_name')) unique_together = ('device', 'name') @@ -642,10 +627,6 @@ class FrontPort(ComponentModel, CableTermination): ] ) - csv_headers = [ - 'device', 'name', 'label', 'type', 'mark_connected', 'rear_port', 'rear_port_position', 'description', - ] - class Meta: ordering = ('device', '_name') unique_together = ( @@ -690,8 +671,6 @@ class RearPort(ComponentModel, CableTermination): ] ) - csv_headers = ['device', 'name', 'label', 'type', 'mark_connected', 'positions', 'description'] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -728,8 +707,6 @@ class DeviceBay(ComponentModel): null=True ) - csv_headers = ['device', 'name', 'label', 'installed_device', 'description'] - class Meta: ordering = ('device', '_name') unique_together = ('device', 'name') @@ -812,10 +789,6 @@ class InventoryItem(MPTTModel, ComponentModel): objects = TreeManager() - csv_headers = [ - 'device', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered', 'description', - ] - class Meta: ordering = ('device__id', 'parent__id', '_name') unique_together = ('device', 'parent', 'name') diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index f91b08019..10cd35c13 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -56,8 +56,6 @@ class Manufacturer(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'description'] - class Meta: ordering = ['name'] @@ -372,8 +370,6 @@ class DeviceRole(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'color', 'vm_role', 'description'] - class Meta: ordering = ['name'] @@ -426,8 +422,6 @@ class Platform(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args', 'description'] - class Meta: ordering = ['name'] @@ -585,10 +579,6 @@ class Device(PrimaryModel, ConfigContextModel): objects = ConfigContextModelQuerySet.as_manager() - csv_headers = [ - 'name', 'device_role', 'tenant', 'manufacturer', 'device_type', 'platform', 'serial', 'asset_tag', 'status', - 'site', 'location', 'rack_name', 'position', 'face', 'comments', - ] clone_fields = [ 'device_type', 'device_role', 'tenant', 'platform', 'site', 'location', 'rack', 'status', 'cluster', ] @@ -884,8 +874,6 @@ class VirtualChassis(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'domain', 'master'] - class Meta: ordering = ['name'] verbose_name_plural = 'virtual chassis' diff --git a/netbox/dcim/models/power.py b/netbox/dcim/models/power.py index 81f305512..f81abd328 100644 --- a/netbox/dcim/models/power.py +++ b/netbox/dcim/models/power.py @@ -42,8 +42,6 @@ class PowerPanel(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['site', 'location', 'name'] - class Meta: ordering = ['site', 'name'] unique_together = ['site', 'name'] @@ -126,10 +124,6 @@ class PowerFeed(PrimaryModel, PathEndpoint, CableTermination): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'site', 'power_panel', 'location', 'rack', 'name', 'status', 'type', 'mark_connected', 'supply', 'phase', - 'voltage', 'amperage', 'max_utilization', 'comments', - ] clone_fields = [ 'power_panel', 'rack', 'status', 'type', 'mark_connected', 'supply', 'phase', 'voltage', 'amperage', 'max_utilization', 'available_power', diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index ba9509a15..3370badc3 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -58,8 +58,6 @@ class RackRole(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'color', 'description'] - class Meta: ordering = ['name'] @@ -183,10 +181,6 @@ class Rack(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'site', 'location', 'name', 'facility_id', 'tenant', 'status', 'role', 'type', 'serial', 'asset_tag', 'width', - 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'comments', - ] clone_fields = [ 'site', 'location', 'tenant', 'status', 'role', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', @@ -464,8 +458,6 @@ class RackReservation(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['site', 'location', 'rack', 'units', 'tenant', 'user', 'description'] - class Meta: ordering = ['created', 'pk'] diff --git a/netbox/dcim/models/sites.py b/netbox/dcim/models/sites.py index b6ff7dee4..943e98106 100644 --- a/netbox/dcim/models/sites.py +++ b/netbox/dcim/models/sites.py @@ -54,8 +54,6 @@ class Region(NestedGroupModel): blank=True ) - csv_headers = ['name', 'slug', 'parent', 'description'] - def get_absolute_url(self): return reverse('dcim:region', args=[self.pk]) @@ -98,8 +96,6 @@ class SiteGroup(NestedGroupModel): blank=True ) - csv_headers = ['name', 'slug', 'parent', 'description'] - def get_absolute_url(self): return reverse('dcim:sitegroup', args=[self.pk]) @@ -220,11 +216,6 @@ class Site(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', - 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', - 'contact_email', 'comments', - ] clone_fields = [ 'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email', @@ -280,7 +271,6 @@ class Location(NestedGroupModel): to='extras.ImageAttachment' ) - csv_headers = ['site', 'parent', 'name', 'slug', 'description'] clone_fields = ['site', 'parent', 'description'] class Meta: diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index 5da1fcb5b..bbb153ee5 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -580,11 +580,11 @@ device-bays: db1 = DeviceBayTemplate.objects.first() self.assertEqual(db1.name, 'Device Bay 1') - def test_devicetype_export(self): - + def test_export_objects(self): url = reverse('dcim:devicetype_list') self.add_permissions('dcim.view_devicetype') + # Test default YAML export response = self.client.get('{}?export'.format(url)) self.assertEqual(response.status_code, 200) data = list(yaml.load_all(response.content, Loader=yaml.SafeLoader)) @@ -592,6 +592,11 @@ device-bays: self.assertEqual(data[0]['manufacturer'], 'Manufacturer 1') self.assertEqual(data[0]['model'], 'Device Type 1') + # Test table-based export + response = self.client.get(f'{url}?export=table') + self.assertHttpStatus(response, 200) + self.assertEqual(response.get('Content-Type'), 'text/csv; charset=utf-8') + # # DeviceType components diff --git a/netbox/extras/forms.py b/netbox/extras/forms.py index 47a874705..8acffca6c 100644 --- a/netbox/extras/forms.py +++ b/netbox/extras/forms.py @@ -154,7 +154,7 @@ class TagCSVForm(CSVModelForm): class Meta: model = Tag - fields = Tag.csv_headers + fields = ('name', 'slug', 'color', 'description') help_texts = { 'color': mark_safe('RGB color in hexadecimal (e.g. 00ff00)'), } diff --git a/netbox/extras/models/change_logging.py b/netbox/extras/models/change_logging.py index 638e7c77f..15bd3cbd8 100644 --- a/netbox/extras/models/change_logging.py +++ b/netbox/extras/models/change_logging.py @@ -80,11 +80,6 @@ class ObjectChange(BigIDModel): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'time', 'user', 'user_name', 'request_id', 'action', 'changed_object_type', 'changed_object_id', - 'related_object_type', 'related_object_id', 'object_repr', 'prechange_data', 'postchange_data', - ] - class Meta: ordering = ['-time'] diff --git a/netbox/extras/models/tags.py b/netbox/extras/models/tags.py index 9b4c8c92e..afeeee53d 100644 --- a/netbox/extras/models/tags.py +++ b/netbox/extras/models/tags.py @@ -26,8 +26,6 @@ class Tag(ChangeLoggedModel, TagBase): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'color', 'description'] - class Meta: ordering = ['name'] diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 8c490233d..cc53dbe34 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -76,7 +76,7 @@ class VRFCSVForm(CustomFieldModelCSVForm): class Meta: model = VRF - fields = VRF.csv_headers + fields = ('name', 'rd', 'tenant', 'enforce_unique', 'description') class VRFBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -152,7 +152,7 @@ class RouteTargetCSVForm(CustomFieldModelCSVForm): class Meta: model = RouteTarget - fields = RouteTarget.csv_headers + fields = ('name', 'description', 'tenant') class RouteTargetBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -214,7 +214,7 @@ class RIRCSVForm(CustomFieldModelCSVForm): class Meta: model = RIR - fields = RIR.csv_headers + fields = ('name', 'slug', 'is_private', 'description') help_texts = { 'name': 'RIR name', } @@ -295,7 +295,7 @@ class AggregateCSVForm(CustomFieldModelCSVForm): class Meta: model = Aggregate - fields = Aggregate.csv_headers + fields = ('prefix', 'rir', 'tenant', 'date_added', 'description') class AggregateBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -369,7 +369,7 @@ class RoleCSVForm(CustomFieldModelCSVForm): class Meta: model = Role - fields = Role.csv_headers + fields = ('name', 'slug', 'weight', 'description') class RoleBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -517,7 +517,10 @@ class PrefixCSVForm(CustomFieldModelCSVForm): class Meta: model = Prefix - fields = Prefix.csv_headers + fields = ( + 'prefix', 'vrf', 'tenant', 'site', 'vlan_group', 'vlan', 'status', 'role', 'is_pool', 'mark_utilized', + 'description', + ) def __init__(self, data=None, *args, **kwargs): super().__init__(data, *args, **kwargs) @@ -1265,7 +1268,7 @@ class VLANGroupCSVForm(CustomFieldModelCSVForm): class Meta: model = VLANGroup - fields = VLANGroup.csv_headers + fields = ('name', 'slug', 'scope_type', 'scope_id', 'description') class VLANGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -1439,7 +1442,7 @@ class VLANCSVForm(CustomFieldModelCSVForm): class Meta: model = VLAN - fields = VLAN.csv_headers + fields = ('site', 'group', 'vid', 'name', 'tenant', 'status', 'role', 'description') help_texts = { 'vid': 'Numeric VLAN ID (1-4095)', 'name': 'VLAN name', @@ -1630,7 +1633,7 @@ class ServiceCSVForm(CustomFieldModelCSVForm): class Meta: model = Service - fields = Service.csv_headers + fields = ('device', 'virtual_machine', 'name', 'protocol', 'ports', 'description') class ServiceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 5bb5f85ee..d6b274bbb 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -55,8 +55,6 @@ class RIR(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'is_private', 'description'] - class Meta: ordering = ['name'] verbose_name = 'RIR' @@ -100,7 +98,6 @@ class Aggregate(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['prefix', 'rir', 'tenant', 'date_added', 'description'] clone_fields = [ 'rir', 'tenant', 'date_added', 'description', ] @@ -191,8 +188,6 @@ class Role(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'weight', 'description'] - class Meta: ordering = ['weight', 'name'] @@ -284,10 +279,6 @@ class Prefix(PrimaryModel): objects = PrefixQuerySet.as_manager() - csv_headers = [ - 'prefix', 'vrf', 'tenant', 'site', 'vlan_group', 'vlan', 'status', 'role', 'is_pool', 'mark_utilized', - 'description', - ] clone_fields = [ 'site', 'vrf', 'tenant', 'vlan', 'status', 'role', 'is_pool', 'mark_utilized', 'description', ] @@ -575,10 +566,6 @@ class IPAddress(PrimaryModel): objects = IPAddressManager() - csv_headers = [ - 'address', 'vrf', 'tenant', 'status', 'role', 'assigned_object_type', 'assigned_object_id', 'is_primary', - 'dns_name', 'description', - ] clone_fields = [ 'vrf', 'tenant', 'status', 'role', 'description', ] diff --git a/netbox/ipam/models/services.py b/netbox/ipam/models/services.py index ebb8f2889..9efe7fed7 100644 --- a/netbox/ipam/models/services.py +++ b/netbox/ipam/models/services.py @@ -67,8 +67,6 @@ class Service(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['device', 'virtual_machine', 'name', 'protocol', 'ports', 'description'] - class Meta: ordering = ('protocol', 'ports', 'pk') # (protocol, port) may be non-unique diff --git a/netbox/ipam/models/vlans.py b/netbox/ipam/models/vlans.py index 738c8aff1..4ba8d7041 100644 --- a/netbox/ipam/models/vlans.py +++ b/netbox/ipam/models/vlans.py @@ -54,8 +54,6 @@ class VLANGroup(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'scope_type', 'scope_id', 'description'] - class Meta: ordering = ('name', 'pk') # Name may be non-unique unique_together = [ @@ -148,7 +146,6 @@ class VLAN(PrimaryModel): objects = VLANQuerySet.as_manager() - csv_headers = ['site', 'group', 'vid', 'name', 'tenant', 'status', 'role', 'description'] clone_fields = [ 'site', 'group', 'tenant', 'status', 'role', 'description', ] diff --git a/netbox/ipam/models/vrfs.py b/netbox/ipam/models/vrfs.py index c88ce81c1..c8e703520 100644 --- a/netbox/ipam/models/vrfs.py +++ b/netbox/ipam/models/vrfs.py @@ -60,7 +60,6 @@ class VRF(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'rd', 'tenant', 'enforce_unique', 'description'] clone_fields = [ 'tenant', 'enforce_unique', 'description', ] @@ -103,8 +102,6 @@ class RouteTarget(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'description', 'tenant'] - class Meta: ordering = ['name'] diff --git a/netbox/tenancy/forms.py b/netbox/tenancy/forms.py index d53748055..992964de1 100644 --- a/netbox/tenancy/forms.py +++ b/netbox/tenancy/forms.py @@ -41,7 +41,7 @@ class TenantGroupCSVForm(CustomFieldModelCSVForm): class Meta: model = TenantGroup - fields = TenantGroup.csv_headers + fields = ('name', 'slug', 'parent', 'description') class TenantGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -99,7 +99,7 @@ class TenantCSVForm(CustomFieldModelCSVForm): class Meta: model = Tenant - fields = Tenant.csv_headers + fields = ('name', 'slug', 'group', 'description', 'comments') class TenantBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): diff --git a/netbox/tenancy/models.py b/netbox/tenancy/models.py index 85087d529..10bd8c7b0 100644 --- a/netbox/tenancy/models.py +++ b/netbox/tenancy/models.py @@ -40,8 +40,6 @@ class TenantGroup(NestedGroupModel): blank=True ) - csv_headers = ['name', 'slug', 'parent', 'description'] - class Meta: ordering = ['name'] @@ -80,7 +78,6 @@ class Tenant(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'group', 'description', 'comments'] clone_fields = [ 'group', 'description', ] diff --git a/netbox/utilities/testing/views.py b/netbox/utilities/testing/views.py index cf408b9ec..83958225a 100644 --- a/netbox/utilities/testing/views.py +++ b/netbox/utilities/testing/views.py @@ -452,10 +452,9 @@ class ViewTestCases: url = self._get_url('list') # Test default CSV export - if hasattr(self.model, 'csv_headers'): - response = self.client.get(f'{url}?export') - self.assertHttpStatus(response, 200) - self.assertEqual(response.get('Content-Type'), 'text/csv; charset=utf-8') + response = self.client.get(f'{url}?export') + self.assertHttpStatus(response, 200) + self.assertEqual(response.get('Content-Type'), 'text/csv; charset=utf-8') # Test table-based export response = self.client.get(f'{url}?export=table') diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index 02290a4e9..5600fd525 100644 --- a/netbox/virtualization/forms.py +++ b/netbox/virtualization/forms.py @@ -43,7 +43,7 @@ class ClusterTypeCSVForm(CustomFieldModelCSVForm): class Meta: model = ClusterType - fields = ClusterType.csv_headers + fields = ('name', 'slug', 'description') class ClusterTypeBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -79,7 +79,7 @@ class ClusterGroupCSVForm(CustomFieldModelCSVForm): class Meta: model = ClusterGroup - fields = ClusterGroup.csv_headers + fields = ('name', 'slug', 'description') class ClusterGroupBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -174,7 +174,7 @@ class ClusterCSVForm(CustomFieldModelCSVForm): class Meta: model = Cluster - fields = Cluster.csv_headers + fields = ('name', 'type', 'group', 'site', 'comments') class ClusterBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -468,7 +468,9 @@ class VirtualMachineCSVForm(CustomFieldModelCSVForm): class Meta: model = VirtualMachine - fields = VirtualMachine.csv_headers + fields = ( + 'name', 'status', 'role', 'cluster', 'tenant', 'platform', 'vcpus', 'memory', 'disk', 'comments', + ) class VirtualMachineBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): @@ -735,7 +737,9 @@ class VMInterfaceCSVForm(CSVModelForm): class Meta: model = VMInterface - fields = VMInterface.csv_headers + fields = ( + 'virtual_machine', 'name', 'enabled', 'mac_address', 'mtu', 'description', 'mode', + ) def clean_enabled(self): # Make sure enabled is True when it's not included in the uploaded data diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index c68fe9e01..4f8683114 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -50,8 +50,6 @@ class ClusterType(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'description'] - class Meta: ordering = ['name'] @@ -86,8 +84,6 @@ class ClusterGroup(OrganizationalModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'slug', 'description'] - class Meta: ordering = ['name'] @@ -143,7 +139,6 @@ class Cluster(PrimaryModel): objects = RestrictedQuerySet.as_manager() - csv_headers = ['name', 'type', 'group', 'site', 'comments'] clone_fields = [ 'type', 'group', 'tenant', 'site', ] @@ -263,9 +258,6 @@ class VirtualMachine(PrimaryModel, ConfigContextModel): objects = ConfigContextModelQuerySet.as_manager() - csv_headers = [ - 'name', 'status', 'role', 'cluster', 'tenant', 'platform', 'vcpus', 'memory', 'disk', 'comments', - ] clone_fields = [ 'cluster', 'tenant', 'platform', 'status', 'role', 'vcpus', 'memory', 'disk', ] @@ -387,10 +379,6 @@ class VMInterface(PrimaryModel, BaseInterface): objects = RestrictedQuerySet.as_manager() - csv_headers = [ - 'virtual_machine', 'name', 'enabled', 'mac_address', 'mtu', 'description', 'mode', - ] - class Meta: verbose_name = 'interface' ordering = ('virtual_machine', CollateAsChar('_name'))