Ticket #11700: 11700.diff
File 11700.diff, 4.3 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/options.py
31 31 class IncorrectLookupParameters(Exception): 32 32 pass 33 33 34 def changelist_request_is_popup(request): 35 from django.contrib.admin.views.main import IS_POPUP_VAR 36 return IS_POPUP_VAR in request.GET 37 34 38 # Defaults for formfield_overrides. ModelAdmin subclasses can change this 35 39 # by adding to ModelAdmin.formfield_overrides. 36 40 … … 480 484 if self.actions is None: 481 485 return [] 482 486 487 # Do not show actions in popups 488 if changelist_request_is_popup(request): 489 return [] 490 483 491 actions = [] 484 492 485 493 # Gather actions from the admin site first … … 962 970 except ValueError: 963 971 pass 964 972 973 # disallow list-editing in popups 974 if changelist_request_is_popup(request): 975 list_editable_for_request = () 976 else: 977 list_editable_for_request = self.list_editable 978 965 979 ChangeList = self.get_changelist(request) 966 980 try: 967 cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter, 968 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) 981 cl = ChangeList(request, self.model, list_display, 982 self.list_display_links, self.list_filter, 983 self.date_hierarchy, self.search_fields, 984 self.list_select_related, self.list_per_page, 985 list_editable_for_request, self) 969 986 except IncorrectLookupParameters: 970 987 # Wacky lookup parameters were given, so redirect to the main 971 988 # changelist page, without parameters, and pass an 'invalid=1' … … 1016 1033 formset = cl.formset = None 1017 1034 1018 1035 # Handle POSTed bulk-edit data. 1019 if (request.method == "POST" and self.list_editableand1036 if (request.method == "POST" and list_editable_for_request and 1020 1037 '_save' in request.POST and not action_failed): 1021 1038 FormSet = self.get_changelist_formset(request) 1022 1039 formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list) … … 1046 1063 return HttpResponseRedirect(request.get_full_path()) 1047 1064 1048 1065 # Handle GET -- construct a formset for display. 1049 elif self.list_editable:1066 elif list_editable_for_request: 1050 1067 FormSet = self.get_changelist_formset(request) 1051 1068 formset = cl.formset = FormSet(queryset=cl.result_list) 1052 1069 -
tests/regressiontests/admin_views/tests.py
1317 1317 self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False) 1318 1318 self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2) 1319 1319 1320 def test_list_editable_popup(self): 1321 """ Fields should not be list-editable in popups. """ 1322 response = self.client.get('/test_admin/admin/admin_views/person/') 1323 self.assertNotEqual(response.context['cl'].list_editable, ()) 1324 response = self.client.get('/test_admin/admin/admin_views/person/?pop') 1325 self.assertEqual(response.context['cl'].list_editable, ()) 1320 1326 1321 1327 1322 1323 1328 class AdminSearchTest(TestCase): 1324 1329 fixtures = ['admin-views-users','multiple-child-classes'] 1325 1330 … … 1555 1560 response = self.client.get('/test_admin/admin/admin_views/subscriber/') 1556 1561 self.assertContains(response, '0 of 2 selected') 1557 1562 1563 def test_popup_actions(self): 1564 """ Actions should not be shown in popups. """ 1565 response = self.client.get('/test_admin/admin/admin_views/subscriber/') 1566 self.assertNotEquals(response.context["action_form"], None) 1567 response = self.client.get( 1568 '/test_admin/admin/admin_views/subscriber/?pop') 1569 self.assertEquals(response.context["action_form"], None) 1558 1570 1571 1559 1572 class TestCustomChangeList(TestCase): 1560 1573 fixtures = ['admin-views-users.xml'] 1561 1574 urlbit = 'admin'