Author: lukeplant
Date: 2011-05-05 15:03:17 -0700 (Thu, 05 May 2011)
New Revision: 16162

Modified:
   django/trunk/django/contrib/admin/options.py
   django/trunk/tests/regressiontests/admin_views/models.py
   django/trunk/tests/regressiontests/admin_views/tests.py
Log:
Fixed #15964 - Do not order admin actions by description

Thanks to julien for the report and patch.

Modified: django/trunk/django/contrib/admin/options.py
===================================================================
--- django/trunk/django/contrib/admin/options.py        2011-05-05 20:49:35 UTC 
(rev 16161)
+++ django/trunk/django/contrib/admin/options.py        2011-05-05 22:03:17 UTC 
(rev 16162)
@@ -576,9 +576,7 @@
         # 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

Modified: django/trunk/tests/regressiontests/admin_views/models.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/models.py    2011-05-05 
20:49:35 UTC (rev 16161)
+++ django/trunk/tests/regressiontests/admin_views/models.py    2011-05-05 
22:03:17 UTC (rev 16162)
@@ -341,13 +341,15 @@
         'f...@example.com',
         ['t...@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)

Modified: django/trunk/tests/regressiontests/admin_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/tests.py     2011-05-05 
20:49:35 UTC (rev 16161)
+++ django/trunk/tests/regressiontests/admin_views/tests.py     2011-05-05 
22:03:17 UTC (rev 16162)
@@ -1971,6 +1971,20 @@
         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/')

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to