diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2011-05-05 22:03:17 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2011-05-05 22:03:17 +0000 |
| commit | 8eccb728ccd97a07b9281d3a7c2c6bac105f285f (patch) | |
| tree | 669c578c2cbac4ac2621530660d34f9a9d98dd35 | |
| parent | d11acfd20959ec0d1baf93f8521e1077337b9c3b (diff) | |
Fixed #15964 - Do not order admin actions by description
Thanks to julien for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16162 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/admin/options.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/models.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 14 |
3 files changed, 18 insertions, 4 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 787f8567e3..c603210e8b 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -576,9 +576,7 @@ class ModelAdmin(BaseModelAdmin): # get_action might have returned None, so filter any of those out. actions = filter(None, actions) - # Convert the actions into a SortedDict keyed by name - # and sorted by description. - actions.sort(key=lambda k: k[2].lower()) + # Convert the actions into a SortedDict keyed by name. actions = SortedDict([ (name, (func, name, desc)) for func, name, desc in actions diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index 6e34ee1272..854fb60e70 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -341,13 +341,15 @@ def external_mail(modeladmin, request, selected): 'from@example.com', ['to@example.com'] ).send() +external_mail.short_description = 'External mail (Another awesome action)' def redirect_to(modeladmin, request, selected): from django.http import HttpResponseRedirect return HttpResponseRedirect('/some-where-else/') +redirect_to.short_description = 'Redirect to (Awesome action)' class ExternalSubscriberAdmin(admin.ModelAdmin): - actions = [external_mail, redirect_to] + actions = [redirect_to, external_mail] class Media(models.Model): name = models.CharField(max_length=60) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 0537160cc0..25740bccea 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -1971,6 +1971,20 @@ class AdminActionsTest(TestCase): response = self.client.post(url, action_data) self.assertRedirects(response, url) + def test_actions_ordering(self): + """ + Ensure that actions are ordered as expected. + Refs #15964. + """ + response = self.client.get('/test_admin/admin/admin_views/externalsubscriber/') + self.assertTrue('''<label>Action: <select name="action"> +<option value="" selected="selected">---------</option> +<option value="delete_selected">Delete selected external subscribers</option> +<option value="redirect_to">Redirect to (Awesome action)</option> +<option value="external_mail">External mail (Another awesome action)</option> +</select>'''in response.content, + ) + def test_model_without_action(self): "Tests a ModelAdmin without any action" response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/') |
