Ticket #15964: 15964.admin-actions-ordering.2.diff

File 15964.admin-actions-ordering.2.diff, 2.7 KB (added by Julien Phalip, 13 years ago)

Added reference to ticket number in the tests

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 787f856..c603210 100644
    a b class ModelAdmin(BaseModelAdmin):  
    576576        # get_action might have returned None, so filter any of those out.
    577577        actions = filter(None, actions)
    578578
    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.
    582580        actions = SortedDict([
    583581            (name, (func, name, desc))
    584582            for func, name, desc in actions
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index 6e34ee1..854fb60 100644
    a b def external_mail(modeladmin, request, selected):  
    341341        'from@example.com',
    342342        ['to@example.com']
    343343    ).send()
     344external_mail.short_description = 'External mail (Another awesome action)'
    344345
    345346def redirect_to(modeladmin, request, selected):
    346347    from django.http import HttpResponseRedirect
    347348    return HttpResponseRedirect('/some-where-else/')
     349redirect_to.short_description = 'Redirect to (Awesome action)'
    348350
    349351class ExternalSubscriberAdmin(admin.ModelAdmin):
    350     actions = [external_mail, redirect_to]
     352    actions = [redirect_to, external_mail]
    351353
    352354class Media(models.Model):
    353355    name = models.CharField(max_length=60)
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 0537160..efc4acb 100644
    a b class AdminActionsTest(TestCase):  
    19711971        response = self.client.post(url, action_data)
    19721972        self.assertRedirects(response, url)
    19731973
     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       
    19741988    def test_model_without_action(self):
    19751989        "Tests a ModelAdmin without any action"
    19761990        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
Back to Top