Code

Ticket #13081: 13081.diff

File 13081.diff, 1.7 KB (added by SmileyChris, 4 years ago)
Line 
1diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
2index 531ce4d..50033c4 100644
3--- a/django/contrib/admin/options.py
4+++ b/django/contrib/admin/options.py
5@@ -757,7 +757,7 @@ class ModelAdmin(BaseModelAdmin):
6             if isinstance(response, HttpResponse):
7                 return response
8             else:
9-                return HttpResponseRedirect(".")
10+                return HttpResponseRedirect(request.get_full_path())
11         else:
12             msg = _("No action selected.")
13             self.message_user(request, msg)
14diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
15index abb28de..d8e4066 100644
16--- a/tests/regressiontests/admin_views/tests.py
17+++ b/tests/regressiontests/admin_views/tests.py
18@@ -1375,6 +1375,21 @@ class AdminActionsTest(TestCase):
19         response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
20         self.failUnlessEqual(response.status_code, 302)
21 
22+    def test_default_redirect(self):
23+        """
24+        Test that actions which don't return an HttpResponse are redirected to
25+        the same page, retaining the querystring (which may contain changelist
26+        information).
27+        """
28+        action_data = {
29+            ACTION_CHECKBOX_NAME: [1],
30+            'action' : 'external_mail',
31+            'index': 0,
32+        }
33+        url = '/test_admin/admin/admin_views/externalsubscriber/?ot=asc&o=1'
34+        response = self.client.post(url, action_data)
35+        self.assertRedirects(response, url)
36+
37     def test_model_without_action(self):
38         "Tests a ModelAdmin without any action"
39         response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')