mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 17:59:11 -06:00
Fixes #4239: Fix exception when selecting all filtered objects during bulk edit
This commit is contained in:
parent
9128dc961c
commit
1c72d75b62
@ -10,6 +10,7 @@
|
|||||||
* [#4228](https://github.com/netbox-community/netbox/issues/4228) - Improve fit of device images in rack elevations
|
* [#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
|
* [#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
|
* [#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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -34,12 +34,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
{% if bulk_edit_url and permissions.change %}
|
{% if bulk_edit_url and permissions.change %}
|
||||||
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if bulk_querystring %}?{{ bulk_querystring }}{% elif request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm" disabled="disabled">
|
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm" disabled="disabled">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit All
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit All
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if bulk_delete_url and permissions.delete %}
|
{% if bulk_delete_url and permissions.delete %}
|
||||||
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if bulk_querystring %}?{{ bulk_querystring }}{% elif request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm" disabled="disabled">
|
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm" disabled="disabled">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete All
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete All
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -51,12 +51,12 @@
|
|||||||
<div class="pull-left noprint">
|
<div class="pull-left noprint">
|
||||||
{% block bulk_buttons %}{% endblock %}
|
{% block bulk_buttons %}{% endblock %}
|
||||||
{% if bulk_edit_url and permissions.change %}
|
{% if bulk_edit_url and permissions.change %}
|
||||||
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}" class="btn btn-warning btn-sm">
|
<button type="submit" name="_edit" formaction="{% url bulk_edit_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-warning btn-sm">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit Selected
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit Selected
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if bulk_delete_url and permissions.delete %}
|
{% if bulk_delete_url and permissions.delete %}
|
||||||
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}" class="btn btn-danger btn-sm">
|
<button type="submit" name="_delete" formaction="{% url bulk_delete_url %}{% if request.GET %}?{{ request.GET.urlencode }}{% endif %}" class="btn btn-danger btn-sm">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete Selected
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -626,12 +626,13 @@ class BulkEditView(GetReturnURLMixin, View):
|
|||||||
|
|
||||||
model = self.queryset.model
|
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 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:
|
if request.POST.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]
|
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:
|
if '_apply' in request.POST:
|
||||||
form = self.form(model, 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))
|
messages.error(self.request, "{} failed validation: {}".format(obj, e))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Pass the PK list as initial data to avoid binding the form
|
form = self.form(model, initial={'pk': pk_list})
|
||||||
initial_data = querydict_to_dict(post_data)
|
|
||||||
form = self.form(model, initial=initial_data)
|
|
||||||
|
|
||||||
# Retrieve objects being edited
|
# 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:
|
if not table.rows:
|
||||||
messages.warning(request, "No {} were selected.".format(model._meta.verbose_name_plural))
|
messages.warning(request, "No {} were selected.".format(model._meta.verbose_name_plural))
|
||||||
return redirect(self.get_return_url(request))
|
return redirect(self.get_return_url(request))
|
||||||
|
Loading…
Reference in New Issue
Block a user