Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@11837 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8a59084c3a34db9b55c1ef426916f758185b9e29 1 parent 627f462
Karen Tracey authored December 12, 2009
1  AUTHORS
@@ -397,6 +397,7 @@ answer newbie questions, and generally made Django that much better:
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
6  django/contrib/admin/options.py
@@ -692,6 +692,9 @@ def response_action(self, request, queryset):
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,6 +706,9 @@ def response_action(self, request, queryset):
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
30  tests/regressiontests/admin_views/tests.py
@@ -1157,7 +1157,6 @@ def test_action_column_class(self):
1157 1157
         self.assert_('action-checkbox-column' in response.content,
1158 1158
             "Expected an action-checkbox-column in response")
1159 1159
 
1160  
-
1161 1160
     def test_multiple_actions_form(self):
1162 1161
         """
1163 1162
         Test that actions come from the form whose submit button was pressed (#10618).
@@ -1175,6 +1174,35 @@ def test_multiple_actions_form(self):
1175 1174
         self.assertEquals(len(mail.outbox), 1)
1176 1175
         self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action')
1177 1176
 
  1177
+    def test_user_message_on_none_selected(self):
  1178
+        """
  1179
+        User should see a warning when 'Go' is pressed and no items are selected.
  1180
+        """
  1181
+        action_data = {
  1182
+            ACTION_CHECKBOX_NAME: [],
  1183
+            'action' : 'delete_selected',
  1184
+            'index': 0,
  1185
+        }
  1186
+        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
  1187
+        msg = """Items must be selected in order to perform actions on them. No items have been changed."""
  1188
+        self.assertContains(response, msg)
  1189
+        self.failUnlessEqual(Subscriber.objects.count(), 2)
  1190
+
  1191
+    def test_user_message_on_no_action(self):
  1192
+        """
  1193
+        User should see a warning when 'Go' is pressed and no action is selected.
  1194
+        """
  1195
+        action_data = {
  1196
+            ACTION_CHECKBOX_NAME: [1, 2],
  1197
+            'action' : '',
  1198
+            'index': 0,
  1199
+        }
  1200
+        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
  1201
+        msg = """No action selected."""
  1202
+        self.assertContains(response, msg)
  1203
+        self.failUnlessEqual(Subscriber.objects.count(), 2)
  1204
+
  1205
+
1178 1206
 class TestInlineNotEditable(TestCase):
1179 1207
     fixtures = ['admin-views-users.xml']
1180 1208
 

0 notes on commit 8a59084

Please sign in to comment.
Something went wrong with that request. Please try again.