From 1c72d75b62992d27b812b205941649586b05fae4 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 21 Feb 2020 20:44:53 -0500 Subject: [PATCH] Fixes #4239: Fix exception when selecting all filtered objects during bulk edit --- docs/release-notes/version-2.7.md | 1 + netbox/templates/utilities/obj_list.html | 8 ++++---- netbox/utilities/views.py | 17 ++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 8b10aa76b..26ba370bd 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -10,6 +10,7 @@ * [#4228](https://github.com/netbox-community/netbox/issues/4228) - Improve fit of device images in rack elevations * [#4232](https://github.com/netbox-community/netbox/issues/4232) - Enforce consistent background striping in rack elevations * [#4235](https://github.com/netbox-community/netbox/issues/4235) - Fix API representation of `content_type` for export templates +* [#4239](https://github.com/netbox-community/netbox/issues/4239) - Fix exception when selecting all filtered objects during bulk edit --- diff --git a/netbox/templates/utilities/obj_list.html b/netbox/templates/utilities/obj_list.html index fe70edd3b..d35520313 100644 --- a/netbox/templates/utilities/obj_list.html +++ b/netbox/templates/utilities/obj_list.html @@ -34,12 +34,12 @@
{% if bulk_edit_url and permissions.change %} - {% endif %} {% if bulk_delete_url and permissions.delete %} - {% endif %} @@ -51,12 +51,12 @@
{% block bulk_buttons %}{% endblock %} {% if bulk_edit_url and permissions.change %} - {% endif %} {% if bulk_delete_url and permissions.delete %} - {% endif %} diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py index 19a6d655e..3d9b638fb 100644 --- a/netbox/utilities/views.py +++ b/netbox/utilities/views.py @@ -626,12 +626,13 @@ class BulkEditView(GetReturnURLMixin, View): model = self.queryset.model - # Create a mutable copy of the POST data - post_data = request.POST.copy() - # If we are editing *all* objects in the queryset, replace the PK list with all matched objects. - if post_data.get('_all') and self.filterset is not None: - post_data['pk'] = [obj.pk for obj in self.filterset(request.GET, model.objects.only('pk')).qs] + if request.POST.get('_all') and self.filterset is not None: + pk_list = [ + obj.pk for obj in self.filterset(request.GET, model.objects.only('pk')).qs + ] + else: + pk_list = request.POST.getlist('pk') if '_apply' in request.POST: form = self.form(model, request.POST) @@ -715,12 +716,10 @@ class BulkEditView(GetReturnURLMixin, View): messages.error(self.request, "{} failed validation: {}".format(obj, e)) else: - # Pass the PK list as initial data to avoid binding the form - initial_data = querydict_to_dict(post_data) - form = self.form(model, initial=initial_data) + form = self.form(model, initial={'pk': pk_list}) # Retrieve objects being edited - table = self.table(self.queryset.filter(pk__in=post_data.getlist('pk')), orderable=False) + table = self.table(self.queryset.filter(pk__in=pk_list), orderable=False) if not table.rows: messages.warning(request, "No {} were selected.".format(model._meta.verbose_name_plural)) return redirect(self.get_return_url(request))