Skip to content

Commit 61b61b1

Browse files
committed
Fixes #7664: Preserve initial form data when bulk edit validation fails
1 parent d0b8558 commit 61b61b1

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [#7643](https://github.com/netbox-community/netbox/issues/7643) - Fix circuit assignment when creating multiple terminations simultaneously
1717
* [#7644](https://github.com/netbox-community/netbox/issues/7644) - Prevent inadvertent deletion of prior change records when deleting objects (#7333 revisited)
1818
* [#7647](https://github.com/netbox-community/netbox/issues/7647) - Require interface assignment when designating IP address as primary for device/VM during CSV import
19+
* [#7664](https://github.com/netbox-community/netbox/issues/7664) - Preserve initial form data when bulk edit validation fails
1920
* [#7717](https://github.com/netbox-community/netbox/issues/7717) - Restore missing tags column on IP range table
2021

2122
---

netbox/netbox/views/generic.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,21 @@ def post(self, request, **kwargs):
777777
else:
778778
pk_list = request.POST.getlist('pk')
779779

780+
# Include the PK list as initial data for the form
781+
initial_data = {'pk': pk_list}
782+
783+
# Check for other contextual data needed for the form. We avoid passing all of request.GET because the
784+
# filter values will conflict with the bulk edit form fields.
785+
# TODO: Find a better way to accomplish this
786+
if 'device' in request.GET:
787+
initial_data['device'] = request.GET.get('device')
788+
elif 'device_type' in request.GET:
789+
initial_data['device_type'] = request.GET.get('device_type')
790+
elif 'virtual_machine' in request.GET:
791+
initial_data['virtual_machine'] = request.GET.get('virtual_machine')
792+
780793
if '_apply' in request.POST:
781-
form = self.form(model, request.POST)
794+
form = self.form(model, request.POST, initial=initial_data)
782795
restrict_form_fields(form, request.user)
783796

784797
if form.is_valid():
@@ -867,18 +880,6 @@ def post(self, request, **kwargs):
867880
logger.debug("Form validation failed")
868881

869882
else:
870-
# Include the PK list as initial data for the form
871-
initial_data = {'pk': pk_list}
872-
873-
# Check for other contextual data needed for the form. We avoid passing all of request.GET because the
874-
# filter values will conflict with the bulk edit form fields.
875-
# TODO: Find a better way to accomplish this
876-
if 'device' in request.GET:
877-
initial_data['device'] = request.GET.get('device')
878-
elif 'device_type' in request.GET:
879-
initial_data['device_type'] = request.GET.get('device_type')
880-
elif 'virtual_machine' in request.GET:
881-
initial_data['virtual_machine'] = request.GET.get('virtual_machine')
882883

883884
form = self.form(model, initial=initial_data)
884885
restrict_form_fields(form, request.user)

0 commit comments

Comments
 (0)