Ticket #17090: 17090.get_list_display-action_checkbox.diff

File 17090.get_list_display-action_checkbox.diff, 4.8 KB (added by Julien Phalip, 9 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 6be2a64..98e80e3 100644
    a b class ModelAdmin(BaseModelAdmin): 
    342342        self.model = model
    343343        self.opts = model._meta
    344344        self.admin_site = admin_site
    345         if 'action_checkbox' not in self.list_display and self.actions is not None:
    346             self.list_display = ['action_checkbox'] +  list(self.list_display)
    347         if not self.list_display_links:
    348             for name in self.list_display:
    349                 if name != 'action_checkbox':
    350                     self.list_display_links = [name]
    351                     break
    352345        super(ModelAdmin, self).__init__()
    353346
    354347    def get_inline_instances(self, request):
    class ModelAdmin(BaseModelAdmin): 
    11051098        actions = self.get_actions(request)
    11061099
    11071100        # Remove action checkboxes if there aren't any actions available.
    1108         list_display = list(self.get_list_display(request))
    1109         if not actions:
    1110             try:
    1111                 list_display.remove('action_checkbox')
    1112             except ValueError:
    1113                 pass
     1101        list_display = self.get_list_display(request)
     1102
     1103        list_display_links = self.list_display_links
     1104        if not self.list_display_links and list_display:
     1105            list_display_links = list(list_display)[:1]
     1106       
     1107        if actions:
     1108            list_display = ['action_checkbox'] +  list(list_display)
    11141109
    11151110        ChangeList = self.get_changelist(request)
    11161111        try:
    1117             cl = ChangeList(request, self.model, list_display, self.list_display_links,
    1118                 self.list_filter, self.date_hierarchy, self.search_fields,
    1119                 self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self)
     1112            cl = ChangeList(request, self.model, list_display,
     1113                list_display_links, self.list_filter, self.date_hierarchy,
     1114                self.search_fields, self.list_select_related,
     1115                self.list_per_page, self.list_max_show_all, self.list_editable,
     1116                self)
    11201117        except IncorrectLookupParameters:
    11211118            # Wacky lookup parameters were given, so redirect to the main
    11221119            # changelist page, without parameters, and pass an 'invalid=1'
  • tests/regressiontests/admin_changelist/tests.py

    diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
    index 5f2ebff..a081c98 100644
    a b class ChangeListTests(TestCase): 
    4848        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    4949        context = Context({'cl': cl})
    5050        table_output = template.render(context)
    51         row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % (new_child.id, new_child.id)
     51        row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % new_child.id
    5252        self.assertFalse(table_output.find(row_html) == -1,
    5353            'Failed to find expected row element: %s' % table_output)
    5454
    class ChangeListTests(TestCase): 
    6868        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    6969        context = Context({'cl': cl})
    7070        table_output = template.render(context)
    71         row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % (new_child.id, new_child.id)
     71        row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % new_child.id
    7272        self.assertFalse(table_output.find(row_html) == -1,
    7373            'Failed to find expected row element: %s' % table_output)
    7474
  • tests/regressiontests/admin_registration/tests.py

    diff --git a/tests/regressiontests/admin_registration/tests.py b/tests/regressiontests/admin_registration/tests.py
    index 1ba8bb1..1b2d291 100644
    a b class TestRegistration(TestCase): 
    4242                           search_fields=["name"], list_display=['__str__'])
    4343        self.assertEqual(self.site._registry[Person].search_fields, ['name'])
    4444        self.assertEqual(self.site._registry[Person].list_display,
    45                          ['action_checkbox', '__str__'])
     45                         ['__str__'])
    4646        self.assertTrue(self.site._registry[Person].save_on_top)
    4747
    4848    def test_iterable_registration(self):
Back to Top