Fixed #26543 -- Prevented "confirm form submission" browser prompt when reloading after an admin actions failure.
This commit is contained in:
parent
9710677c10
commit
8ba01d1e42
|
@ -1575,14 +1575,19 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
else:
|
else:
|
||||||
action_failed = True
|
action_failed = True
|
||||||
|
|
||||||
|
if action_failed:
|
||||||
|
# Redirect back to the changelist page to avoid resubmitting the
|
||||||
|
# form if the user refreshes the browser or uses the "No, take
|
||||||
|
# me back" button on the action confirmation page.
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
# If we're allowing changelist editing, we need to construct a formset
|
# If we're allowing changelist editing, we need to construct a formset
|
||||||
# for the changelist given all the fields to be edited. Then we'll
|
# for the changelist given all the fields to be edited. Then we'll
|
||||||
# use the formset to validate/process POSTed data.
|
# use the formset to validate/process POSTed data.
|
||||||
formset = cl.formset = None
|
formset = cl.formset = None
|
||||||
|
|
||||||
# Handle POSTed bulk-edit data.
|
# Handle POSTed bulk-edit data.
|
||||||
if (request.method == "POST" and cl.list_editable and
|
if request.method == 'POST' and cl.list_editable and '_save' in request.POST:
|
||||||
'_save' in request.POST and not action_failed):
|
|
||||||
FormSet = self.get_changelist_formset(request)
|
FormSet = self.get_changelist_formset(request)
|
||||||
formset = cl.formset = FormSet(request.POST, request.FILES, queryset=self.get_queryset(request))
|
formset = cl.formset = FormSet(request.POST, request.FILES, queryset=self.get_queryset(request))
|
||||||
if formset.is_valid():
|
if formset.is_valid():
|
||||||
|
|
|
@ -3406,7 +3406,10 @@ action)</option>
|
||||||
'action': 'delete_selected',
|
'action': 'delete_selected',
|
||||||
'index': 0,
|
'index': 0,
|
||||||
}
|
}
|
||||||
response = self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
|
url = reverse('admin:admin_views_subscriber_changelist')
|
||||||
|
response = self.client.post(url, action_data)
|
||||||
|
self.assertRedirects(response, url, fetch_redirect_response=False)
|
||||||
|
response = self.client.get(response.url)
|
||||||
msg = """Items must be selected in order to perform actions on them. No items have been changed."""
|
msg = """Items must be selected in order to perform actions on them. No items have been changed."""
|
||||||
self.assertContains(response, msg)
|
self.assertContains(response, msg)
|
||||||
self.assertEqual(Subscriber.objects.count(), 2)
|
self.assertEqual(Subscriber.objects.count(), 2)
|
||||||
|
@ -3420,7 +3423,10 @@ action)</option>
|
||||||
'action': '',
|
'action': '',
|
||||||
'index': 0,
|
'index': 0,
|
||||||
}
|
}
|
||||||
response = self.client.post(reverse('admin:admin_views_subscriber_changelist'), action_data)
|
url = reverse('admin:admin_views_subscriber_changelist')
|
||||||
|
response = self.client.post(url, action_data)
|
||||||
|
self.assertRedirects(response, url, fetch_redirect_response=False)
|
||||||
|
response = self.client.get(response.url)
|
||||||
msg = """No action selected."""
|
msg = """No action selected."""
|
||||||
self.assertContains(response, msg)
|
self.assertContains(response, msg)
|
||||||
self.assertEqual(Subscriber.objects.count(), 2)
|
self.assertEqual(Subscriber.objects.count(), 2)
|
||||||
|
|
Loading…
Reference in New Issue