Author: kmtracey Date: 2009-12-12 15:51:47 -0600 (Sat, 12 Dec 2009) New Revision: 11837
Modified: django/trunk/AUTHORS django/trunk/django/contrib/admin/options.py django/trunk/tests/regressiontests/admin_views/tests.py Log: Fixed #12218: Added some helpful messages when Go is pressed in admin actions and there is nothing to do because no action was selected or no items are selected. Modified: django/trunk/AUTHORS =================================================================== --- django/trunk/AUTHORS 2009-12-12 20:55:46 UTC (rev 11836) +++ django/trunk/AUTHORS 2009-12-12 21:51:47 UTC (rev 11837) @@ -397,6 +397,7 @@ Jozko Skrablin <jozko.skrab...@gmail.com> Ben Slavin <benjamin.sla...@gmail.com> sloonz <simon.l...@insa-lyon.fr> + Paul Smith <blinkylight...@gmail.com> Warren Smith <war...@wandrsmith.net> sm...@smurf.noris.de Vsevolod Solovyov Modified: django/trunk/django/contrib/admin/options.py =================================================================== --- django/trunk/django/contrib/admin/options.py 2009-12-12 20:55:46 UTC (rev 11836) +++ django/trunk/django/contrib/admin/options.py 2009-12-12 21:51:47 UTC (rev 11837) @@ -692,6 +692,9 @@ # perform an action on it, so bail. selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME) if not selected: + # Reminder that something needs to be selected or nothing will happen + msg = "Items must be selected in order to perform actions on them. No items have been changed." + self.message_user(request, _(msg)) return None response = func(self, request, queryset.filter(pk__in=selected)) @@ -703,6 +706,9 @@ return response else: return HttpResponseRedirect(".") + else: + msg = "No action selected." + self.message_user(request, _(msg)) @csrf_protect @transaction.commit_on_success Modified: django/trunk/tests/regressiontests/admin_views/tests.py =================================================================== --- django/trunk/tests/regressiontests/admin_views/tests.py 2009-12-12 20:55:46 UTC (rev 11836) +++ django/trunk/tests/regressiontests/admin_views/tests.py 2009-12-12 21:51:47 UTC (rev 11837) @@ -1157,7 +1157,6 @@ self.assert_('action-checkbox-column' in response.content, "Expected an action-checkbox-column in response") - def test_multiple_actions_form(self): """ Test that actions come from the form whose submit button was pressed (#10618). @@ -1175,6 +1174,35 @@ self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action') + def test_user_message_on_none_selected(self): + """ + User should see a warning when 'Go' is pressed and no items are selected. + """ + action_data = { + ACTION_CHECKBOX_NAME: [], + 'action' : 'delete_selected', + 'index': 0, + } + response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) + msg = """Items must be selected in order to perform actions on them. No items have been changed.""" + self.assertContains(response, msg) + self.failUnlessEqual(Subscriber.objects.count(), 2) + + def test_user_message_on_no_action(self): + """ + User should see a warning when 'Go' is pressed and no action is selected. + """ + action_data = { + ACTION_CHECKBOX_NAME: [1, 2], + 'action' : '', + 'index': 0, + } + response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) + msg = """No action selected.""" + self.assertContains(response, msg) + self.failUnlessEqual(Subscriber.objects.count(), 2) + + class TestInlineNotEditable(TestCase): fixtures = ['admin-views-users.xml'] -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.