mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
[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
This commit is contained in:
parent
31618e3ea4
commit
6c91e6ecbc
1
AUTHORS
1
AUTHORS
@ -394,6 +394,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Ben Slavin <benjamin.slavin@gmail.com>
|
Ben Slavin <benjamin.slavin@gmail.com>
|
||||||
sloonz <simon.lipp@insa-lyon.fr>
|
sloonz <simon.lipp@insa-lyon.fr>
|
||||||
SmileyChris <smileychris@gmail.com>
|
SmileyChris <smileychris@gmail.com>
|
||||||
|
Paul Smith <blinkylights23@gmail.com>
|
||||||
Warren Smith <warren@wandrsmith.net>
|
Warren Smith <warren@wandrsmith.net>
|
||||||
smurf@smurf.noris.de
|
smurf@smurf.noris.de
|
||||||
Vsevolod Solovyov
|
Vsevolod Solovyov
|
||||||
|
@ -689,6 +689,9 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
# perform an action on it, so bail.
|
# perform an action on it, so bail.
|
||||||
selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
|
selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
|
||||||
if not selected:
|
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
|
return None
|
||||||
|
|
||||||
response = func(self, request, queryset.filter(pk__in=selected))
|
response = func(self, request, queryset.filter(pk__in=selected))
|
||||||
@ -700,6 +703,9 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return HttpResponseRedirect(".")
|
return HttpResponseRedirect(".")
|
||||||
|
else:
|
||||||
|
msg = "No action selected."
|
||||||
|
self.message_user(request, _(msg))
|
||||||
|
|
||||||
def add_view(self, request, form_url='', extra_context=None):
|
def add_view(self, request, form_url='', extra_context=None):
|
||||||
"The 'add' admin view for this model."
|
"The 'add' admin view for this model."
|
||||||
|
@ -1156,7 +1156,6 @@ class AdminActionsTest(TestCase):
|
|||||||
self.assert_('action-checkbox-column' in response.content,
|
self.assert_('action-checkbox-column' in response.content,
|
||||||
"Expected an action-checkbox-column in response")
|
"Expected an action-checkbox-column in response")
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_actions_form(self):
|
def test_multiple_actions_form(self):
|
||||||
"""
|
"""
|
||||||
Test that actions come from the form whose submit button was pressed (#10618).
|
Test that actions come from the form whose submit button was pressed (#10618).
|
||||||
@ -1174,6 +1173,35 @@ class AdminActionsTest(TestCase):
|
|||||||
self.assertEquals(len(mail.outbox), 1)
|
self.assertEquals(len(mail.outbox), 1)
|
||||||
self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action')
|
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):
|
class TestInlineNotEditable(TestCase):
|
||||||
fixtures = ['admin-views-users.xml']
|
fixtures = ['admin-views-users.xml']
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user