From 206d578bc3e37d89a6265ce3c95075310560275e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 17 Mar 2023 09:23:40 -0400 Subject: [PATCH] Closes #10242: Redirect to filtered objects list after bulk import (#12001) * Redirect user to filtered objects list after bulk import * Remove obsolete table attribute from bulk import views --- docs/release-notes/version-3.5.md | 1 + netbox/circuits/views.py | 4 --- netbox/core/views.py | 1 - netbox/dcim/tests/test_views.py | 6 ++--- netbox/dcim/views.py | 31 ----------------------- netbox/extras/tests/test_customfields.py | 2 +- netbox/extras/views.py | 7 ----- netbox/ipam/views.py | 17 ------------- netbox/netbox/tests/test_import.py | 2 +- netbox/netbox/views/generic/bulk_views.py | 18 ++++++------- netbox/templates/import_success.html | 17 ------------- netbox/tenancy/views.py | 5 ---- netbox/utilities/testing/views.py | 6 ++--- netbox/virtualization/views.py | 5 ---- netbox/wireless/views.py | 3 --- 15 files changed, 17 insertions(+), 108 deletions(-) delete mode 100644 netbox/templates/import_success.html diff --git a/docs/release-notes/version-3.5.md b/docs/release-notes/version-3.5.md index 7a7335e4b2..e8d81e7d13 100644 --- a/docs/release-notes/version-3.5.md +++ b/docs/release-notes/version-3.5.md @@ -33,6 +33,7 @@ A new ASN range model has been introduced to facilitate the provisioning of new * [#9073](https://github.com/netbox-community/netbox/issues/9073) - Enable syncing config context data from remote sources * [#9653](https://github.com/netbox-community/netbox/issues/9653) - Enable setting a default platform for device types * [#10054](https://github.com/netbox-community/netbox/issues/10054) - Introduce advanced object selector for UI forms +* [#10242](https://github.com/netbox-community/netbox/issues/10242) - Redirect to filter objects list after bulk import * [#10374](https://github.com/netbox-community/netbox/issues/10374) - Require unique tenant names & slugs per group (not globally) * [#10729](https://github.com/netbox-community/netbox/issues/10729) - Add date & time custom field type * [#11254](https://github.com/netbox-community/netbox/issues/11254) - Introduce the `X-Request-ID` HTTP header to annotate the unique ID of each request for change logging diff --git a/netbox/circuits/views.py b/netbox/circuits/views.py index 228b70bb19..25620a8525 100644 --- a/netbox/circuits/views.py +++ b/netbox/circuits/views.py @@ -53,7 +53,6 @@ class ProviderDeleteView(generic.ObjectDeleteView): class ProviderBulkImportView(generic.BulkImportView): queryset = Provider.objects.all() model_form = forms.ProviderImportForm - table = tables.ProviderTable class ProviderBulkEditView(generic.BulkEditView): @@ -115,7 +114,6 @@ class ProviderNetworkDeleteView(generic.ObjectDeleteView): class ProviderNetworkBulkImportView(generic.BulkImportView): queryset = ProviderNetwork.objects.all() model_form = forms.ProviderNetworkImportForm - table = tables.ProviderNetworkTable class ProviderNetworkBulkEditView(generic.BulkEditView): @@ -172,7 +170,6 @@ class CircuitTypeDeleteView(generic.ObjectDeleteView): class CircuitTypeBulkImportView(generic.BulkImportView): queryset = CircuitType.objects.all() model_form = forms.CircuitTypeImportForm - table = tables.CircuitTypeTable class CircuitTypeBulkEditView(generic.BulkEditView): @@ -224,7 +221,6 @@ class CircuitDeleteView(generic.ObjectDeleteView): class CircuitBulkImportView(generic.BulkImportView): queryset = Circuit.objects.all() model_form = forms.CircuitImportForm - table = tables.CircuitTable additional_permissions = [ 'circuits.add_circuittermination', ] diff --git a/netbox/core/views.py b/netbox/core/views.py index 63905228e4..d4baa4eaf4 100644 --- a/netbox/core/views.py +++ b/netbox/core/views.py @@ -70,7 +70,6 @@ class DataSourceDeleteView(generic.ObjectDeleteView): class DataSourceBulkImportView(generic.BulkImportView): queryset = DataSource.objects.all() model_form = forms.DataSourceImportForm - table = tables.DataSourceTable class DataSourceBulkEditView(generic.BulkEditView): diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index eef78c6c66..886de5a252 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -1994,7 +1994,7 @@ def test_module_bulk_replication(self): } initial_count = Module.objects.count() - self.assertHttpStatus(self.client.post(**request), 200) + self.assertHttpStatus(self.client.post(**request), 302) self.assertEqual(Module.objects.count(), initial_count + len(csv_data) - 1) self.assertEqual(Interface.objects.filter(device=device).count(), 0) @@ -2010,7 +2010,7 @@ def test_module_bulk_replication(self): } initial_count = Module.objects.count() - self.assertHttpStatus(self.client.post(**request), 200) + self.assertHttpStatus(self.client.post(**request), 302) self.assertEqual(Module.objects.count(), initial_count + len(csv_data) - 1) self.assertEqual(Interface.objects.filter(device=device).count(), 5) @@ -2086,7 +2086,7 @@ def test_module_bulk_adoption(self): } initial_count = self._get_queryset().count() - self.assertHttpStatus(self.client.post(**request), 200) + self.assertHttpStatus(self.client.post(**request), 302) self.assertEqual(self._get_queryset().count(), initial_count + len(csv_data) - 1) # Re-retrieve interface to get new module id diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 38eb302a86..4f3ce23e86 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -27,7 +27,6 @@ from virtualization.models import VirtualMachine from . import filtersets, forms, tables from .choices import DeviceFaceChoices -from .constants import NONCONNECTABLE_IFACE_TYPES from .models import * CABLE_TERMINATION_TYPES = { @@ -240,7 +239,6 @@ class RegionDeleteView(generic.ObjectDeleteView): class RegionBulkImportView(generic.BulkImportView): queryset = Region.objects.all() model_form = forms.RegionImportForm - table = tables.RegionTable class RegionBulkEditView(generic.BulkEditView): @@ -316,7 +314,6 @@ class SiteGroupDeleteView(generic.ObjectDeleteView): class SiteGroupBulkImportView(generic.BulkImportView): queryset = SiteGroup.objects.all() model_form = forms.SiteGroupImportForm - table = tables.SiteGroupTable class SiteGroupBulkEditView(generic.BulkEditView): @@ -422,7 +419,6 @@ class SiteDeleteView(generic.ObjectDeleteView): class SiteBulkImportView(generic.BulkImportView): queryset = Site.objects.all() model_form = forms.SiteImportForm - table = tables.SiteTable class SiteBulkEditView(generic.BulkEditView): @@ -499,7 +495,6 @@ class LocationDeleteView(generic.ObjectDeleteView): class LocationBulkImportView(generic.BulkImportView): queryset = Location.objects.all() model_form = forms.LocationImportForm - table = tables.LocationTable class LocationBulkEditView(generic.BulkEditView): @@ -568,7 +563,6 @@ class RackRoleDeleteView(generic.ObjectDeleteView): class RackRoleBulkImportView(generic.BulkImportView): queryset = RackRole.objects.all() model_form = forms.RackRoleImportForm - table = tables.RackRoleTable class RackRoleBulkEditView(generic.BulkEditView): @@ -728,7 +722,6 @@ class RackDeleteView(generic.ObjectDeleteView): class RackBulkImportView(generic.BulkImportView): queryset = Rack.objects.all() model_form = forms.RackImportForm - table = tables.RackTable class RackBulkEditView(generic.BulkEditView): @@ -781,7 +774,6 @@ class RackReservationDeleteView(generic.ObjectDeleteView): class RackReservationImportView(generic.BulkImportView): queryset = RackReservation.objects.all() model_form = forms.RackReservationImportForm - table = tables.RackReservationTable def save_object(self, object_form, request): """ @@ -854,7 +846,6 @@ class ManufacturerDeleteView(generic.ObjectDeleteView): class ManufacturerBulkImportView(generic.BulkImportView): queryset = Manufacturer.objects.all() model_form = forms.ManufacturerImportForm - table = tables.ManufacturerTable class ManufacturerBulkEditView(generic.BulkEditView): @@ -1083,7 +1074,6 @@ class DeviceTypeImportView(generic.BulkImportView): ] queryset = DeviceType.objects.all() model_form = forms.DeviceTypeImportForm - table = tables.DeviceTypeTable related_object_forms = { 'console-ports': forms.ConsolePortTemplateImportForm, 'console-server-ports': forms.ConsoleServerPortTemplateImportForm, @@ -1275,7 +1265,6 @@ class ModuleTypeImportView(generic.BulkImportView): ] queryset = ModuleType.objects.all() model_form = forms.ModuleTypeImportForm - table = tables.ModuleTypeTable related_object_forms = { 'console-ports': forms.ConsolePortTemplateImportForm, 'console-server-ports': forms.ConsoleServerPortTemplateImportForm, @@ -1722,7 +1711,6 @@ class DeviceRoleDeleteView(generic.ObjectDeleteView): class DeviceRoleBulkImportView(generic.BulkImportView): queryset = DeviceRole.objects.all() model_form = forms.DeviceRoleImportForm - table = tables.DeviceRoleTable class DeviceRoleBulkEditView(generic.BulkEditView): @@ -1786,7 +1774,6 @@ class PlatformDeleteView(generic.ObjectDeleteView): class PlatformBulkImportView(generic.BulkImportView): queryset = Platform.objects.all() model_form = forms.PlatformImportForm - table = tables.PlatformTable class PlatformBulkEditView(generic.BulkEditView): @@ -2047,7 +2034,6 @@ class DeviceConfigContextView(ObjectConfigContextView): class DeviceBulkImportView(generic.BulkImportView): queryset = Device.objects.all() model_form = forms.DeviceImportForm - table = tables.DeviceImportTable def save_object(self, object_form, request): obj = object_form.save() @@ -2125,7 +2111,6 @@ class ModuleDeleteView(generic.ObjectDeleteView): class ModuleBulkImportView(generic.BulkImportView): queryset = Module.objects.all() model_form = forms.ModuleImportForm - table = tables.ModuleTable class ModuleBulkEditView(generic.BulkEditView): @@ -2178,7 +2163,6 @@ class ConsolePortDeleteView(generic.ObjectDeleteView): class ConsolePortBulkImportView(generic.BulkImportView): queryset = ConsolePort.objects.all() model_form = forms.ConsolePortImportForm - table = tables.ConsolePortTable class ConsolePortBulkEditView(generic.BulkEditView): @@ -2243,7 +2227,6 @@ class ConsoleServerPortDeleteView(generic.ObjectDeleteView): class ConsoleServerPortBulkImportView(generic.BulkImportView): queryset = ConsoleServerPort.objects.all() model_form = forms.ConsoleServerPortImportForm - table = tables.ConsoleServerPortTable class ConsoleServerPortBulkEditView(generic.BulkEditView): @@ -2308,7 +2291,6 @@ class PowerPortDeleteView(generic.ObjectDeleteView): class PowerPortBulkImportView(generic.BulkImportView): queryset = PowerPort.objects.all() model_form = forms.PowerPortImportForm - table = tables.PowerPortTable class PowerPortBulkEditView(generic.BulkEditView): @@ -2373,7 +2355,6 @@ class PowerOutletDeleteView(generic.ObjectDeleteView): class PowerOutletBulkImportView(generic.BulkImportView): queryset = PowerOutlet.objects.all() model_form = forms.PowerOutletImportForm - table = tables.PowerOutletTable class PowerOutletBulkEditView(generic.BulkEditView): @@ -2484,7 +2465,6 @@ class InterfaceDeleteView(generic.ObjectDeleteView): class InterfaceBulkImportView(generic.BulkImportView): queryset = Interface.objects.all() model_form = forms.InterfaceImportForm - table = tables.InterfaceTable class InterfaceBulkEditView(generic.BulkEditView): @@ -2549,7 +2529,6 @@ class FrontPortDeleteView(generic.ObjectDeleteView): class FrontPortBulkImportView(generic.BulkImportView): queryset = FrontPort.objects.all() model_form = forms.FrontPortImportForm - table = tables.FrontPortTable class FrontPortBulkEditView(generic.BulkEditView): @@ -2614,7 +2593,6 @@ class RearPortDeleteView(generic.ObjectDeleteView): class RearPortBulkImportView(generic.BulkImportView): queryset = RearPort.objects.all() model_form = forms.RearPortImportForm - table = tables.RearPortTable class RearPortBulkEditView(generic.BulkEditView): @@ -2679,7 +2657,6 @@ class ModuleBayDeleteView(generic.ObjectDeleteView): class ModuleBayBulkImportView(generic.BulkImportView): queryset = ModuleBay.objects.all() model_form = forms.ModuleBayImportForm - table = tables.ModuleBayTable class ModuleBayBulkEditView(generic.BulkEditView): @@ -2805,7 +2782,6 @@ def post(self, request, pk): class DeviceBayBulkImportView(generic.BulkImportView): queryset = DeviceBay.objects.all() model_form = forms.DeviceBayImportForm - table = tables.DeviceBayTable class DeviceBayBulkEditView(generic.BulkEditView): @@ -2864,7 +2840,6 @@ class InventoryItemDeleteView(generic.ObjectDeleteView): class InventoryItemBulkImportView(generic.BulkImportView): queryset = InventoryItem.objects.all() model_form = forms.InventoryItemImportForm - table = tables.InventoryItemTable class InventoryItemBulkEditView(generic.BulkEditView): @@ -2921,7 +2896,6 @@ class InventoryItemRoleDeleteView(generic.ObjectDeleteView): class InventoryItemRoleBulkImportView(generic.BulkImportView): queryset = InventoryItemRole.objects.all() model_form = forms.InventoryItemRoleImportForm - table = tables.InventoryItemRoleTable class InventoryItemRoleBulkEditView(generic.BulkEditView): @@ -3116,7 +3090,6 @@ class CableDeleteView(generic.ObjectDeleteView): class CableBulkImportView(generic.BulkImportView): queryset = Cable.objects.all() model_form = forms.CableImportForm - table = tables.CableTable class CableBulkEditView(generic.BulkEditView): @@ -3399,7 +3372,6 @@ def post(self, request, pk): class VirtualChassisBulkImportView(generic.BulkImportView): queryset = VirtualChassis.objects.all() model_form = forms.VirtualChassisImportForm - table = tables.VirtualChassisTable class VirtualChassisBulkEditView(generic.BulkEditView): @@ -3456,7 +3428,6 @@ class PowerPanelDeleteView(generic.ObjectDeleteView): class PowerPanelBulkImportView(generic.BulkImportView): queryset = PowerPanel.objects.all() model_form = forms.PowerPanelImportForm - table = tables.PowerPanelTable class PowerPanelBulkEditView(generic.BulkEditView): @@ -3504,7 +3475,6 @@ class PowerFeedDeleteView(generic.ObjectDeleteView): class PowerFeedBulkImportView(generic.BulkImportView): queryset = PowerFeed.objects.all() model_form = forms.PowerFeedImportForm - table = tables.PowerFeedTable class PowerFeedBulkEditView(generic.BulkEditView): @@ -3566,7 +3536,6 @@ class VirtualDeviceContextDeleteView(generic.ObjectDeleteView): class VirtualDeviceContextBulkImportView(generic.BulkImportView): queryset = VirtualDeviceContext.objects.all() model_form = forms.VirtualDeviceContextImportForm - table = tables.VirtualDeviceContextTable class VirtualDeviceContextBulkEditView(generic.BulkEditView): diff --git a/netbox/extras/tests/test_customfields.py b/netbox/extras/tests/test_customfields.py index f29a11e0e9..6a3a3d0743 100644 --- a/netbox/extras/tests/test_customfields.py +++ b/netbox/extras/tests/test_customfields.py @@ -1047,7 +1047,7 @@ def test_import(self): csv_data = '\n'.join(','.join(row) for row in data) response = self.client.post(reverse('dcim:site_import'), {'data': csv_data, 'format': 'csv'}) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 302) self.assertEqual(Site.objects.count(), 3) # Validate data for site 1 diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 39dff15f62..07829429f7 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -55,7 +55,6 @@ class CustomFieldDeleteView(generic.ObjectDeleteView): class CustomFieldBulkImportView(generic.BulkImportView): queryset = CustomField.objects.all() model_form = forms.CustomFieldImportForm - table = tables.CustomFieldTable class CustomFieldBulkEditView(generic.BulkEditView): @@ -101,7 +100,6 @@ class CustomLinkDeleteView(generic.ObjectDeleteView): class CustomLinkBulkImportView(generic.BulkImportView): queryset = CustomLink.objects.all() model_form = forms.CustomLinkImportForm - table = tables.CustomLinkTable class CustomLinkBulkEditView(generic.BulkEditView): @@ -149,7 +147,6 @@ class ExportTemplateDeleteView(generic.ObjectDeleteView): class ExportTemplateBulkImportView(generic.BulkImportView): queryset = ExportTemplate.objects.all() model_form = forms.ExportTemplateImportForm - table = tables.ExportTemplateTable class ExportTemplateBulkEditView(generic.BulkEditView): @@ -221,7 +218,6 @@ class SavedFilterDeleteView(SavedFilterMixin, generic.ObjectDeleteView): class SavedFilterBulkImportView(SavedFilterMixin, generic.BulkImportView): queryset = SavedFilter.objects.all() model_form = forms.SavedFilterImportForm - table = tables.SavedFilterTable class SavedFilterBulkEditView(SavedFilterMixin, generic.BulkEditView): @@ -267,7 +263,6 @@ class WebhookDeleteView(generic.ObjectDeleteView): class WebhookBulkImportView(generic.BulkImportView): queryset = Webhook.objects.all() model_form = forms.WebhookImportForm - table = tables.WebhookTable class WebhookBulkEditView(generic.BulkEditView): @@ -336,7 +331,6 @@ class TagDeleteView(generic.ObjectDeleteView): class TagBulkImportView(generic.BulkImportView): queryset = Tag.objects.all() model_form = forms.TagImportForm - table = tables.TagTable class TagBulkEditView(generic.BulkEditView): @@ -489,7 +483,6 @@ class ConfigTemplateDeleteView(generic.ObjectDeleteView): class ConfigTemplateBulkImportView(generic.BulkImportView): queryset = ConfigTemplate.objects.all() model_form = forms.ConfigTemplateImportForm - table = tables.ConfigTemplateTable class ConfigTemplateBulkEditView(generic.BulkEditView): diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 0a8fb7f61b..1d1ef1d064 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -71,7 +71,6 @@ class VRFDeleteView(generic.ObjectDeleteView): class VRFBulkImportView(generic.BulkImportView): queryset = VRF.objects.all() model_form = forms.VRFImportForm - table = tables.VRFTable class VRFBulkEditView(generic.BulkEditView): @@ -117,7 +116,6 @@ class RouteTargetDeleteView(generic.ObjectDeleteView): class RouteTargetBulkImportView(generic.BulkImportView): queryset = RouteTarget.objects.all() model_form = forms.RouteTargetImportForm - table = tables.RouteTargetTable class RouteTargetBulkEditView(generic.BulkEditView): @@ -174,7 +172,6 @@ class RIRDeleteView(generic.ObjectDeleteView): class RIRBulkImportView(generic.BulkImportView): queryset = RIR.objects.all() model_form = forms.RIRImportForm - table = tables.RIRTable class RIRBulkEditView(generic.BulkEditView): @@ -245,7 +242,6 @@ class ASNRangeDeleteView(generic.ObjectDeleteView): class ASNRangeBulkImportView(generic.BulkImportView): queryset = ASNRange.objects.all() model_form = forms.ASNRangeImportForm - table = tables.ASNRangeTable class ASNRangeBulkEditView(generic.BulkEditView): @@ -308,7 +304,6 @@ class ASNDeleteView(generic.ObjectDeleteView): class ASNBulkImportView(generic.BulkImportView): queryset = ASN.objects.all() model_form = forms.ASNImportForm - table = tables.ASNTable class ASNBulkEditView(generic.BulkEditView): @@ -395,7 +390,6 @@ class AggregateDeleteView(generic.ObjectDeleteView): class AggregateBulkImportView(generic.BulkImportView): queryset = Aggregate.objects.all() model_form = forms.AggregateImportForm - table = tables.AggregateTable class AggregateBulkEditView(generic.BulkEditView): @@ -460,7 +454,6 @@ class RoleDeleteView(generic.ObjectDeleteView): class RoleBulkImportView(generic.BulkImportView): queryset = Role.objects.all() model_form = forms.RoleImportForm - table = tables.RoleTable class RoleBulkEditView(generic.BulkEditView): @@ -638,7 +631,6 @@ class PrefixDeleteView(generic.ObjectDeleteView): class PrefixBulkImportView(generic.BulkImportView): queryset = Prefix.objects.all() model_form = forms.PrefixImportForm - table = tables.PrefixTable class PrefixBulkEditView(generic.BulkEditView): @@ -702,7 +694,6 @@ class IPRangeDeleteView(generic.ObjectDeleteView): class IPRangeBulkImportView(generic.BulkImportView): queryset = IPRange.objects.all() model_form = forms.IPRangeImportForm - table = tables.IPRangeTable class IPRangeBulkEditView(generic.BulkEditView): @@ -864,7 +855,6 @@ class IPAddressBulkCreateView(generic.BulkCreateView): class IPAddressBulkImportView(generic.BulkImportView): queryset = IPAddress.objects.all() model_form = forms.IPAddressImportForm - table = tables.IPAddressTable class IPAddressBulkEditView(generic.BulkEditView): @@ -934,7 +924,6 @@ class VLANGroupDeleteView(generic.ObjectDeleteView): class VLANGroupBulkImportView(generic.BulkImportView): queryset = VLANGroup.objects.all() model_form = forms.VLANGroupImportForm - table = tables.VLANGroupTable class VLANGroupBulkEditView(generic.BulkEditView): @@ -1016,7 +1005,6 @@ class FHRPGroupDeleteView(generic.ObjectDeleteView): class FHRPGroupBulkImportView(generic.BulkImportView): queryset = FHRPGroup.objects.all() model_form = forms.FHRPGroupImportForm - table = tables.FHRPGroupTable class FHRPGroupBulkEditView(generic.BulkEditView): @@ -1132,7 +1120,6 @@ class VLANDeleteView(generic.ObjectDeleteView): class VLANBulkImportView(generic.BulkImportView): queryset = VLAN.objects.all() model_form = forms.VLANImportForm - table = tables.VLANTable class VLANBulkEditView(generic.BulkEditView): @@ -1178,7 +1165,6 @@ class ServiceTemplateDeleteView(generic.ObjectDeleteView): class ServiceTemplateBulkImportView(generic.BulkImportView): queryset = ServiceTemplate.objects.all() model_form = forms.ServiceTemplateImportForm - table = tables.ServiceTemplateTable class ServiceTemplateBulkEditView(generic.BulkEditView): @@ -1231,7 +1217,6 @@ class ServiceDeleteView(generic.ObjectDeleteView): class ServiceBulkImportView(generic.BulkImportView): queryset = Service.objects.all() model_form = forms.ServiceImportForm - table = tables.ServiceTable class ServiceBulkEditView(generic.BulkEditView): @@ -1290,7 +1275,6 @@ class L2VPNDeleteView(generic.ObjectDeleteView): class L2VPNBulkImportView(generic.BulkImportView): queryset = L2VPN.objects.all() model_form = forms.L2VPNImportForm - table = tables.L2VPNTable class L2VPNBulkEditView(generic.BulkEditView): @@ -1337,7 +1321,6 @@ class L2VPNTerminationDeleteView(generic.ObjectDeleteView): class L2VPNTerminationBulkImportView(generic.BulkImportView): queryset = L2VPNTermination.objects.all() model_form = forms.L2VPNTerminationImportForm - table = tables.L2VPNTerminationTable class L2VPNTerminationBulkEditView(generic.BulkEditView): diff --git a/netbox/netbox/tests/test_import.py b/netbox/netbox/tests/test_import.py index 88d2605c5d..73f775bd76 100644 --- a/netbox/netbox/tests/test_import.py +++ b/netbox/netbox/tests/test_import.py @@ -42,7 +42,7 @@ def test_valid_tags(self): self.assertHttpStatus(self.client.get(self._get_url('import')), 200) # Test POST with permission - self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) + self.assertHttpStatus(self.client.post(self._get_url('import'), data), 302) regions = Region.objects.all() self.assertEqual(regions.count(), 4) region = Region.objects.get(slug="region-4") diff --git a/netbox/netbox/views/generic/bulk_views.py b/netbox/netbox/views/generic/bulk_views.py index 6ca25f3918..549e1cd8c8 100644 --- a/netbox/netbox/views/generic/bulk_views.py +++ b/netbox/netbox/views/generic/bulk_views.py @@ -11,6 +11,7 @@ from django.forms import ModelMultipleChoiceField, MultipleHiddenInput from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse from django.utils.safestring import mark_safe from django_tables2.export import TableExport @@ -22,6 +23,7 @@ from utilities.forms.bulk_import import ImportForm from utilities.htmx import is_embedded, is_htmx from utilities.permissions import get_permission_for_model +from utilities.utils import get_viewname from utilities.views import GetReturnURLMixin from .base import BaseMultiObjectView from .mixins import ActionsMixin, TableMixin @@ -435,7 +437,7 @@ def get(self, request): def post(self, request): logger = logging.getLogger('netbox.views.BulkImportView') - + model = self.model_form._meta.model form = ImportForm(request.POST, request.FILES) if form.is_valid(): @@ -450,18 +452,14 @@ def post(self, request): if self.queryset.filter(pk__in=[obj.pk for obj in new_objs]).count() != len(new_objs): raise PermissionsViolation - # Compile a table containing the imported objects - obj_table = self.table(new_objs) - if new_objs: - msg = 'Imported {} {}'.format(len(new_objs), new_objs[0]._meta.verbose_name_plural) + msg = f"Imported {len(new_objs)} {model._meta.verbose_name_plural}" logger.info(msg) messages.success(request, msg) - return render(request, "import_success.html", { - 'table': obj_table, - 'return_url': self.get_return_url(request), - }) + view_name = get_viewname(model, action='list') + results_url = f"{reverse(view_name)}?created_by_request={request.id}" + return redirect(results_url) except (AbortTransaction, ValidationError): clear_webhooks.send(sender=self) @@ -475,7 +473,7 @@ def post(self, request): logger.debug("Form validation failed") return render(request, self.template_name, { - 'model': self.model_form._meta.model, + 'model': model, 'form': form, 'fields': self.model_form().fields, 'return_url': self.get_return_url(request), diff --git a/netbox/templates/import_success.html b/netbox/templates/import_success.html deleted file mode 100644 index 122555b810..0000000000 --- a/netbox/templates/import_success.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends 'base/layout.html' %} -{% load render_table from django_tables2 %} - -{% block title %}Import Completed{% endblock %} - -{% block content %} -
- {% render_table table 'inc/table.html' %} -
- {% if return_url %} - View All - {% endif %} - - - Import More - -{% endblock content %} diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index b71702d65c..6248ddddf8 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -60,7 +60,6 @@ class TenantGroupDeleteView(generic.ObjectDeleteView): class TenantGroupBulkImportView(generic.BulkImportView): queryset = TenantGroup.objects.all() model_form = forms.TenantGroupImportForm - table = tables.TenantGroupTable class TenantGroupBulkEditView(generic.BulkEditView): @@ -150,7 +149,6 @@ class TenantDeleteView(generic.ObjectDeleteView): class TenantBulkImportView(generic.BulkImportView): queryset = Tenant.objects.all() model_form = forms.TenantImportForm - table = tables.TenantTable class TenantBulkEditView(generic.BulkEditView): @@ -212,7 +210,6 @@ class ContactGroupDeleteView(generic.ObjectDeleteView): class ContactGroupBulkImportView(generic.BulkImportView): queryset = ContactGroup.objects.all() model_form = forms.ContactGroupImportForm - table = tables.ContactGroupTable class ContactGroupBulkEditView(generic.BulkEditView): @@ -278,7 +275,6 @@ class ContactRoleDeleteView(generic.ObjectDeleteView): class ContactRoleBulkImportView(generic.BulkImportView): queryset = ContactRole.objects.all() model_form = forms.ContactRoleImportForm - table = tables.ContactRoleTable class ContactRoleBulkEditView(generic.BulkEditView): @@ -325,7 +321,6 @@ class ContactDeleteView(generic.ObjectDeleteView): class ContactBulkImportView(generic.BulkImportView): queryset = Contact.objects.all() model_form = forms.ContactImportForm - table = tables.ContactTable class ContactBulkEditView(generic.BulkEditView): diff --git a/netbox/utilities/testing/views.py b/netbox/utilities/testing/views.py index 4a1b2207d5..dc17548a26 100644 --- a/netbox/utilities/testing/views.py +++ b/netbox/utilities/testing/views.py @@ -592,7 +592,7 @@ def test_bulk_import_objects_with_permission(self): self.assertHttpStatus(self.client.get(self._get_url('import')), 200) # Test POST with permission - self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) + self.assertHttpStatus(self.client.post(self._get_url('import'), data), 302) self.assertEqual(self._get_queryset().count(), initial_count + len(self.csv_data) - 1) @override_settings(EXEMPT_VIEW_PERMISSIONS=['*']) @@ -617,7 +617,7 @@ def test_bulk_update_objects_with_permission(self): obj_perm.object_types.add(ContentType.objects.get_for_model(self.model)) # Test POST with permission - self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) + self.assertHttpStatus(self.client.post(self._get_url('import'), data), 302) self.assertEqual(initial_count, self._get_queryset().count()) reader = csv.DictReader(array, delimiter=',') @@ -659,7 +659,7 @@ def test_bulk_import_objects_with_constrained_permission(self): obj_perm.save() # Import permitted objects - self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) + self.assertHttpStatus(self.client.post(self._get_url('import'), data), 302) self.assertEqual(self._get_queryset().count(), initial_count + len(self.csv_data) - 1) class BulkEditObjectsViewTestCase(ModelViewTestCase): diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index 7feff18d56..4209f05033 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -59,7 +59,6 @@ class ClusterTypeDeleteView(generic.ObjectDeleteView): class ClusterTypeBulkImportView(generic.BulkImportView): queryset = ClusterType.objects.all() model_form = forms.ClusterTypeImportForm - table = tables.ClusterTypeTable class ClusterTypeBulkEditView(generic.BulkEditView): @@ -121,7 +120,6 @@ class ClusterGroupBulkImportView(generic.BulkImportView): cluster_count=count_related(Cluster, 'group') ) model_form = forms.ClusterGroupImportForm - table = tables.ClusterGroupTable class ClusterGroupBulkEditView(generic.BulkEditView): @@ -213,7 +211,6 @@ class ClusterDeleteView(generic.ObjectDeleteView): class ClusterBulkImportView(generic.BulkImportView): queryset = Cluster.objects.all() model_form = forms.ClusterImportForm - table = tables.ClusterTable class ClusterBulkEditView(generic.BulkEditView): @@ -376,7 +373,6 @@ class VirtualMachineDeleteView(generic.ObjectDeleteView): class VirtualMachineBulkImportView(generic.BulkImportView): queryset = VirtualMachine.objects.all() model_form = forms.VirtualMachineImportForm - table = tables.VirtualMachineTable class VirtualMachineBulkEditView(generic.BulkEditView): @@ -458,7 +454,6 @@ class VMInterfaceDeleteView(generic.ObjectDeleteView): class VMInterfaceBulkImportView(generic.BulkImportView): queryset = VMInterface.objects.all() model_form = forms.VMInterfaceImportForm - table = tables.VMInterfaceTable class VMInterfaceBulkEditView(generic.BulkEditView): diff --git a/netbox/wireless/views.py b/netbox/wireless/views.py index 22b1ff15dd..e1eb6fd7d5 100644 --- a/netbox/wireless/views.py +++ b/netbox/wireless/views.py @@ -52,7 +52,6 @@ class WirelessLANGroupDeleteView(generic.ObjectDeleteView): class WirelessLANGroupBulkImportView(generic.BulkImportView): queryset = WirelessLANGroup.objects.all() model_form = forms.WirelessLANGroupImportForm - table = tables.WirelessLANGroupTable class WirelessLANGroupBulkEditView(generic.BulkEditView): @@ -123,7 +122,6 @@ class WirelessLANDeleteView(generic.ObjectDeleteView): class WirelessLANBulkImportView(generic.BulkImportView): queryset = WirelessLAN.objects.all() model_form = forms.WirelessLANImportForm - table = tables.WirelessLANTable class WirelessLANBulkEditView(generic.BulkEditView): @@ -169,7 +167,6 @@ class WirelessLinkDeleteView(generic.ObjectDeleteView): class WirelessLinkBulkImportView(generic.BulkImportView): queryset = WirelessLink.objects.all() model_form = forms.WirelessLinkImportForm - table = tables.WirelessLinkTable class WirelessLinkBulkEditView(generic.BulkEditView):