Ticket #12281: admin-action-empty-queryset-12281-patch.diff

File admin-action-empty-queryset-12281-patch.diff, 3.0 KB (added by Paul Smith, 15 years ago)

Added tests

  • django/contrib/admin/options.py

     
    692692            # perform an action on it, so bail.
    693693            selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
    694694            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))
    695698                return None
    696699
    697700            response = func(self, request, queryset.filter(pk__in=selected))
     
    703706                return response
    704707            else:
    705708                return HttpResponseRedirect(".")
     709        else:
     710            msg = "No action selected."
     711            self.message_user(request, _(msg))
    706712
    707713    @csrf_protect
    708714    @transaction.commit_on_success
  • tests/regressiontests/admin_views/tests.py

     
    11751175        self.assertEquals(len(mail.outbox), 1)
    11761176        self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action')
    11771177
     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
    11781210class TestInlineNotEditable(TestCase):
    11791211    fixtures = ['admin-views-users.xml']
    11801212
  • AUTHORS

     
    397397    Jozko Skrablin <jozko.skrablin@gmail.com>
    398398    Ben Slavin <benjamin.slavin@gmail.com>
    399399    sloonz <simon.lipp@insa-lyon.fr>
     400    Paul Smith <blinkylights23@gmail.com>
    400401    Warren Smith <warren@wandrsmith.net>
    401402    smurf@smurf.noris.de
    402403    Vsevolod Solovyov
Back to Top