Ticket #12281: admin-action-empty-queryset-12281-patch.diff
File admin-action-empty-queryset-12281-patch.diff, 3.0 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
692 692 # perform an action on it, so bail. 693 693 selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME) 694 694 if not selected: 695 # Reminder that something needs to be selected or nothing will happen 696 msg = "Items must be selected in order to perform actions on them. No items have been changed." 697 self.message_user(request, _(msg)) 695 698 return None 696 699 697 700 response = func(self, request, queryset.filter(pk__in=selected)) … … 703 706 return response 704 707 else: 705 708 return HttpResponseRedirect(".") 709 else: 710 msg = "No action selected." 711 self.message_user(request, _(msg)) 706 712 707 713 @csrf_protect 708 714 @transaction.commit_on_success -
tests/regressiontests/admin_views/tests.py
1175 1175 self.assertEquals(len(mail.outbox), 1) 1176 1176 self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action') 1177 1177 1178 def test_user_message_on_none_selected(self): 1179 """ 1180 User should see a warning when 'Go' is pressed and no items are selected. 1181 """ 1182 action_data = { 1183 ACTION_CHECKBOX_NAME: [], 1184 'action' : 'delete_selected', 1185 'index': 0, 1186 } 1187 response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) 1188 msg = """Items must be selected in order to perform actions on them. No items have been changed.""" 1189 self.assertContains(response, msg) 1190 self.failUnlessEqual(Subscriber.objects.count(), 2) 1191 1192 def test_user_message_on_no_action(self): 1193 """ 1194 User should see a warning when 'Go' is pressed and no action is selected. 1195 """ 1196 action_data = { 1197 ACTION_CHECKBOX_NAME: [1, 2], 1198 'action' : '', 1199 'index': 0, 1200 } 1201 response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) 1202 msg = """No action selected.""" 1203 self.assertContains(response, msg) 1204 self.failUnlessEqual(Subscriber.objects.count(), 2) 1205 1206 1207 1208 1209 1178 1210 class TestInlineNotEditable(TestCase): 1179 1211 fixtures = ['admin-views-users.xml'] 1180 1212 -
AUTHORS
397 397 Jozko Skrablin <jozko.skrablin@gmail.com> 398 398 Ben Slavin <benjamin.slavin@gmail.com> 399 399 sloonz <simon.lipp@insa-lyon.fr> 400 Paul Smith <blinkylights23@gmail.com> 400 401 Warren Smith <warren@wandrsmith.net> 401 402 smurf@smurf.noris.de 402 403 Vsevolod Solovyov