Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #17090 -- Made the API specification for `ModelAdmin.get_list_d…

…isplay()` more consistent with that of `ModelAdmin.list_display` by separating out the admin action check boxes business. This is backwards-incompatible for those who have been using the still-unreleased `get_list_display()` method. Thanks to Ramiro Morales for the review.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17035 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 600c576ac56fc5c0567450c8cb5696f225de7c8d 1 parent 4d79083
@jphalip jphalip authored
View
31 django/contrib/admin/options.py
@@ -342,13 +342,6 @@ def __init__(self, model, admin_site):
self.model = model
self.opts = model._meta
self.admin_site = admin_site
- if 'action_checkbox' not in self.list_display and self.actions is not None:
- self.list_display = ['action_checkbox'] + list(self.list_display)
- if not self.list_display_links:
- for name in self.list_display:
- if name != 'action_checkbox':
- self.list_display_links = [name]
- break
super(ModelAdmin, self).__init__()
def get_inline_instances(self, request):
@@ -1104,19 +1097,23 @@ def changelist_view(self, request, extra_context=None):
# Check actions to see if any are available on this changelist
actions = self.get_actions(request)
- # Remove action checkboxes if there aren't any actions available.
- list_display = list(self.get_list_display(request))
- if not actions:
- try:
- list_display.remove('action_checkbox')
- except ValueError:
- pass
+ list_display = self.get_list_display(request)
+
+ list_display_links = self.list_display_links
+ if not self.list_display_links and list_display:
+ list_display_links = list(list_display)[:1]
+
+ if actions:
+ # Add the action checkboxes if there are any actions available.
+ list_display = ['action_checkbox'] + list(list_display)
ChangeList = self.get_changelist(request)
try:
- cl = ChangeList(request, self.model, list_display, self.list_display_links,
- self.list_filter, self.date_hierarchy, self.search_fields,
- self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self)
+ cl = ChangeList(request, self.model, list_display,
+ list_display_links, self.list_filter, self.date_hierarchy,
+ self.search_fields, self.list_select_related,
+ self.list_per_page, self.list_max_show_all, self.list_editable,
+ self)
except IncorrectLookupParameters:
# Wacky lookup parameters were given, so redirect to the main
# changelist page, without parameters, and pass an 'invalid=1'
View
4 tests/regressiontests/admin_changelist/tests.py
@@ -48,7 +48,7 @@ def test_result_list_empty_changelist_value(self):
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
- 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)
+ row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % new_child.id
self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)
@@ -68,7 +68,7 @@ def test_result_list_html(self):
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
- 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)
+ row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % new_child.id
self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)
View
2  tests/regressiontests/admin_registration/tests.py
@@ -42,7 +42,7 @@ def test_star_star_overrides(self):
search_fields=["name"], list_display=['__str__'])
self.assertEqual(self.site._registry[Person].search_fields, ['name'])
self.assertEqual(self.site._registry[Person].list_display,
- ['action_checkbox', '__str__'])
+ ['__str__'])
self.assertTrue(self.site._registry[Person].save_on_top)
def test_iterable_registration(self):
Please sign in to comment.
Something went wrong with that request. Please try again.