Code

Ticket #11700: 11700.diff

File 11700.diff, 4.3 KB (added by DrMeers, 4 years ago)
Line 
1Index: django/contrib/admin/options.py
2===================================================================
3--- django/contrib/admin/options.py     (revision 13679)
4+++ django/contrib/admin/options.py     (working copy)
5@@ -31,6 +31,10 @@
6 class IncorrectLookupParameters(Exception):
7     pass
8 
9+def changelist_request_is_popup(request):
10+    from django.contrib.admin.views.main import IS_POPUP_VAR
11+    return IS_POPUP_VAR in request.GET
12+
13 # Defaults for formfield_overrides. ModelAdmin subclasses can change this
14 # by adding to ModelAdmin.formfield_overrides.
15 
16@@ -480,6 +484,10 @@
17         if self.actions is None:
18             return []
19 
20+        # Do not show actions in popups
21+        if changelist_request_is_popup(request):
22+            return []
23+
24         actions = []
25 
26         # Gather actions from the admin site first
27@@ -962,10 +970,19 @@
28             except ValueError:
29                 pass
30 
31+        # disallow list-editing in popups
32+        if changelist_request_is_popup(request):
33+            list_editable_for_request = ()
34+        else:
35+            list_editable_for_request = self.list_editable
36+
37         ChangeList = self.get_changelist(request)
38         try:
39-            cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter,
40-                self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
41+            cl = ChangeList(request, self.model, list_display,
42+                            self.list_display_links, self.list_filter,
43+                            self.date_hierarchy, self.search_fields,
44+                            self.list_select_related, self.list_per_page,
45+                            list_editable_for_request, self)
46         except IncorrectLookupParameters:
47             # Wacky lookup parameters were given, so redirect to the main
48             # changelist page, without parameters, and pass an 'invalid=1'
49@@ -1016,7 +1033,7 @@
50         formset = cl.formset = None
51 
52         # Handle POSTed bulk-edit data.
53-        if (request.method == "POST" and self.list_editable and
54+        if (request.method == "POST" and list_editable_for_request and
55                 '_save' in request.POST and not action_failed):
56             FormSet = self.get_changelist_formset(request)
57             formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list)
58@@ -1046,7 +1063,7 @@
59                 return HttpResponseRedirect(request.get_full_path())
60 
61         # Handle GET -- construct a formset for display.
62-        elif self.list_editable:
63+        elif list_editable_for_request:
64             FormSet = self.get_changelist_formset(request)
65             formset = cl.formset = FormSet(queryset=cl.result_list)
66 
67Index: tests/regressiontests/admin_views/tests.py
68===================================================================
69--- tests/regressiontests/admin_views/tests.py  (revision 13679)
70+++ tests/regressiontests/admin_views/tests.py  (working copy)
71@@ -1317,9 +1317,14 @@
72         self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
73         self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
74 
75+    def test_list_editable_popup(self):
76+        """ Fields should not be list-editable in popups. """
77+        response = self.client.get('/test_admin/admin/admin_views/person/')
78+        self.assertNotEqual(response.context['cl'].list_editable, ())
79+        response = self.client.get('/test_admin/admin/admin_views/person/?pop')
80+        self.assertEqual(response.context['cl'].list_editable, ())
81 
82 
83-
84 class AdminSearchTest(TestCase):
85     fixtures = ['admin-views-users','multiple-child-classes']
86 
87@@ -1555,7 +1560,15 @@
88         response = self.client.get('/test_admin/admin/admin_views/subscriber/')
89         self.assertContains(response, '0 of 2 selected')
90 
91+    def test_popup_actions(self):
92+        """ Actions should not be shown in popups. """
93+        response = self.client.get('/test_admin/admin/admin_views/subscriber/')
94+        self.assertNotEquals(response.context["action_form"], None)
95+        response = self.client.get(
96+            '/test_admin/admin/admin_views/subscriber/?pop')
97+        self.assertEquals(response.context["action_form"], None)
98 
99+
100 class TestCustomChangeList(TestCase):
101     fixtures = ['admin-views-users.xml']
102     urlbit = 'admin'