Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 8eccb728ccd97a07b9281d3a7c2c6bac105f285f 1 parent d11acfd
Luke Plant authored May 05, 2011
4  django/contrib/admin/options.py
@@ -576,9 +576,7 @@ def get_actions(self, request):
576 576
         # get_action might have returned None, so filter any of those out.
577 577
         actions = filter(None, actions)
578 578
 
579  
-        # Convert the actions into a SortedDict keyed by name
580  
-        # and sorted by description.
581  
-        actions.sort(key=lambda k: k[2].lower())
  579
+        # Convert the actions into a SortedDict keyed by name.
582 580
         actions = SortedDict([
583 581
             (name, (func, name, desc))
584 582
             for func, name, desc in actions
4  tests/regressiontests/admin_views/models.py
@@ -341,13 +341,15 @@ def external_mail(modeladmin, request, selected):
341 341
         'from@example.com',
342 342
         ['to@example.com']
343 343
     ).send()
  344
+external_mail.short_description = 'External mail (Another awesome action)'
344 345
 
345 346
 def redirect_to(modeladmin, request, selected):
346 347
     from django.http import HttpResponseRedirect
347 348
     return HttpResponseRedirect('/some-where-else/')
  349
+redirect_to.short_description = 'Redirect to (Awesome action)'
348 350
 
349 351
 class ExternalSubscriberAdmin(admin.ModelAdmin):
350  
-    actions = [external_mail, redirect_to]
  352
+    actions = [redirect_to, external_mail]
351 353
 
352 354
 class Media(models.Model):
353 355
     name = models.CharField(max_length=60)
14  tests/regressiontests/admin_views/tests.py
@@ -1971,6 +1971,20 @@ def test_default_redirect(self):
1971 1971
         response = self.client.post(url, action_data)
1972 1972
         self.assertRedirects(response, url)
1973 1973
 
  1974
+    def test_actions_ordering(self):
  1975
+        """
  1976
+        Ensure that actions are ordered as expected.
  1977
+        Refs #15964.
  1978
+        """
  1979
+        response = self.client.get('/test_admin/admin/admin_views/externalsubscriber/')
  1980
+        self.assertTrue('''<label>Action: <select name="action">
  1981
+<option value="" selected="selected">---------</option>
  1982
+<option value="delete_selected">Delete selected external subscribers</option>
  1983
+<option value="redirect_to">Redirect to (Awesome action)</option>
  1984
+<option value="external_mail">External mail (Another awesome action)</option>
  1985
+</select>'''in response.content,
  1986
+        )
  1987
+
1974 1988
     def test_model_without_action(self):
1975 1989
         "Tests a ModelAdmin without any action"
1976 1990
         response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')

0 notes on commit 8eccb72

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