Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12281: 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. 

r11837 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11838 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6c91e6ecbc10b32dd2c0f3f4e68d16647e4fb38d 1 parent 31618e3
Karen Tracey authored December 12, 2009
1  AUTHORS
@@ -394,6 +394,7 @@ answer newbie questions, and generally made Django that much better:
394 394
     Ben Slavin <benjamin.slavin@gmail.com>
395 395
     sloonz <simon.lipp@insa-lyon.fr>
396 396
     SmileyChris <smileychris@gmail.com>
  397
+    Paul Smith <blinkylights23@gmail.com>
397 398
     Warren Smith <warren@wandrsmith.net>
398 399
     smurf@smurf.noris.de
399 400
     Vsevolod Solovyov
6  django/contrib/admin/options.py
@@ -689,6 +689,9 @@ def response_action(self, request, queryset):
689 689
             # perform an action on it, so bail.
690 690
             selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
691 691
             if not selected:
  692
+                # Reminder that something needs to be selected or nothing will happen
  693
+                msg = "Items must be selected in order to perform actions on them. No items have been changed."
  694
+                self.message_user(request, _(msg))
692 695
                 return None
693 696
 
694 697
             response = func(self, request, queryset.filter(pk__in=selected))
@@ -700,6 +703,9 @@ def response_action(self, request, queryset):
700 703
                 return response
701 704
             else:
702 705
                 return HttpResponseRedirect(".")
  706
+        else:
  707
+            msg = "No action selected."
  708
+            self.message_user(request, _(msg))
703 709
 
704 710
     def add_view(self, request, form_url='', extra_context=None):
705 711
         "The 'add' admin view for this model."
30  tests/regressiontests/admin_views/tests.py
@@ -1156,7 +1156,6 @@ def test_action_column_class(self):
1156 1156
         self.assert_('action-checkbox-column' in response.content,
1157 1157
             "Expected an action-checkbox-column in response")
1158 1158
 
1159  
-
1160 1159
     def test_multiple_actions_form(self):
1161 1160
         """
1162 1161
         Test that actions come from the form whose submit button was pressed (#10618).
@@ -1174,6 +1173,35 @@ def test_multiple_actions_form(self):
1174 1173
         self.assertEquals(len(mail.outbox), 1)
1175 1174
         self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action')
1176 1175
 
  1176
+    def test_user_message_on_none_selected(self):
  1177
+        """
  1178
+        User should see a warning when 'Go' is pressed and no items are selected.
  1179
+        """
  1180
+        action_data = {
  1181
+            ACTION_CHECKBOX_NAME: [],
  1182
+            'action' : 'delete_selected',
  1183
+            'index': 0,
  1184
+        }
  1185
+        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
  1186
+        msg = """Items must be selected in order to perform actions on them. No items have been changed."""
  1187
+        self.assertContains(response, msg)
  1188
+        self.failUnlessEqual(Subscriber.objects.count(), 2)
  1189
+
  1190
+    def test_user_message_on_no_action(self):
  1191
+        """
  1192
+        User should see a warning when 'Go' is pressed and no action is selected.
  1193
+        """
  1194
+        action_data = {
  1195
+            ACTION_CHECKBOX_NAME: [1, 2],
  1196
+            'action' : '',
  1197
+            'index': 0,
  1198
+        }
  1199
+        response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
  1200
+        msg = """No action selected."""
  1201
+        self.assertContains(response, msg)
  1202
+        self.failUnlessEqual(Subscriber.objects.count(), 2)
  1203
+
  1204
+
1177 1205
 class TestInlineNotEditable(TestCase):
1178 1206
     fixtures = ['admin-views-users.xml']
1179 1207
 

0 notes on commit 6c91e6e

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