summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-04-06 20:23:33 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-04-06 20:23:33 +0000
commitbb15cee58a43eeb0d060f8a31f9078b3406f195a (patch)
tree7c02dd3d09d32728c54e26374a86bf4f09233968 /tests/regressiontests
parentd0c897d6605a95c3e7826ee7f01ef20979977ebb (diff)
Made a bunch of improvements to admin actions. Be warned: this includes one minor but BACKWARDS-INCOMPATIBLE change.
These changes are: * BACKWARDS-INCOMPATIBLE CHANGE: action functions and action methods now share the same signature: `(modeladmin, request, queryset)`. Actions defined as methods stay the same, but if you've defined an action as a standalone function you'll now need to add that first `modeladmin` argument. * The delete selected action is now a standalone function registered site-wide; this makes disabling it easy. * Fixed #10596: there are now official, documented `AdminSite` APIs for dealing with actions, including a method to disable global actions. You can still re-enable globally-disabled actions on a case-by-case basis. * Fixed #10595: you can now disable actions for a particular `ModelAdmin` by setting `actions` to `None`. * Fixed #10734: actions are now sorted (by name). * Fixed #10618: the action is now taken from the form whose "submit" button you clicked, not arbitrarily the last form on the page. * All of the above is documented and tested. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10408 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/admin_views/models.py13
-rw-r--r--tests/regressiontests/admin_views/tests.py26
2 files changed, 36 insertions, 3 deletions
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 74fc7ecf78..75b4ad2c87 100644
--- a/tests/regressiontests/admin_views/models.py
+++ b/tests/regressiontests/admin_views/models.py
@@ -223,7 +223,7 @@ class Subscriber(models.Model):
return "%s (%s)" % (self.name, self.email)
class SubscriberAdmin(admin.ModelAdmin):
- actions = ['delete_selected', 'mail_admin']
+ actions = ['mail_admin']
def mail_admin(self, request, selected):
EmailMessage(
@@ -236,7 +236,10 @@ class SubscriberAdmin(admin.ModelAdmin):
class ExternalSubscriber(Subscriber):
pass
-def external_mail(request, selected):
+class OldSubscriber(Subscriber):
+ pass
+
+def external_mail(modeladmin, request, selected):
EmailMessage(
'Greetings from a function action',
'This is the test email from a function action',
@@ -244,7 +247,7 @@ def external_mail(request, selected):
['to@example.com']
).send()
-def redirect_to(request, selected):
+def redirect_to(modeladmin, request, selected):
from django.http import HttpResponseRedirect
return HttpResponseRedirect('/some-where-else/')
@@ -285,6 +288,9 @@ class EmptyModelAdmin(admin.ModelAdmin):
def queryset(self, request):
return super(EmptyModelAdmin, self).queryset(request).filter(pk__gt=1)
+class OldSubscriberAdmin(admin.ModelAdmin):
+ actions = None
+
admin.site.register(Article, ArticleAdmin)
admin.site.register(CustomArticle, CustomArticleAdmin)
admin.site.register(Section, save_as=True, inlines=[ArticleInline])
@@ -295,6 +301,7 @@ admin.site.register(Person, PersonAdmin)
admin.site.register(Persona, PersonaAdmin)
admin.site.register(Subscriber, SubscriberAdmin)
admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
+admin.site.register(OldSubscriber, OldSubscriberAdmin)
admin.site.register(Podcast, PodcastAdmin)
admin.site.register(Parent, ParentAdmin)
admin.site.register(EmptyModel, EmptyModelAdmin)
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 7c54c73346..d7bce8fdcd 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -995,6 +995,32 @@ class AdminActionsTest(TestCase):
}
response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
self.failUnlessEqual(response.status_code, 302)
+
+ def test_model_without_action(self):
+ "Tests a ModelAdmin without any action"
+ response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
+ self.assertEquals(response.context["action_form"], None)
+ self.assert_(
+ '<input type="checkbox" class="action-select"' not in response.content,
+ "Found an unexpected action toggle checkboxbox in response"
+ )
+
+ def test_multiple_actions_form(self):
+ """
+ Test that actions come from the form whose submit button was pressed (#10618).
+ """
+ action_data = {
+ ACTION_CHECKBOX_NAME: [1],
+ # Two different actions selected on the two forms...
+ 'action': ['external_mail', 'delete_selected'],
+ # ...but we clicked "go" on the top form.
+ 'index': 0
+ }
+ response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
+
+ # Send mail, don't delete.
+ self.assertEquals(len(mail.outbox), 1)
+ self.assertEquals(mail.outbox[0].subject, 'Greetings from a function action')
class TestInlineNotEditable(TestCase):
fixtures = ['admin-views-users.xml']