diff --git a/django/contrib/admin/media/css/changelists.css b/django/contrib/admin/media/css/changelists.css index 3f8cf3c21b..282833c440 100644 --- a/django/contrib/admin/media/css/changelists.css +++ b/django/contrib/admin/media/css/changelists.css @@ -9,6 +9,8 @@ width: 100%; } +.change-list .hiddenfields { display:none; } + .change-list .filtered table { border-right: 1px solid #ddd; } diff --git a/django/contrib/admin/templates/admin/change_list_results.html b/django/contrib/admin/templates/admin/change_list_results.html index cd2050e895..6d4de2df0e 100644 --- a/django/contrib/admin/templates/admin/change_list_results.html +++ b/django/contrib/admin/templates/admin/change_list_results.html @@ -1,3 +1,8 @@ +{% if result_hidden_fields %} +
%s | ' % (row_class, result_repr)) - if form: + if form and not form[cl.model._meta.pk.name].is_hidden: yield mark_safe(u'%s | ' % force_unicode(form[cl.model._meta.pk.name])) def results(cl): @@ -200,11 +200,18 @@ def results(cl): for res in cl.result_list: yield list(items_for_result(cl, res, None)) +def result_hidden_fields(cl): + if cl.formset: + for res, form in zip(cl.result_list, cl.formset.forms): + if form[cl.model._meta.pk.name].is_hidden: + yield mark_safe(force_unicode(form[cl.model._meta.pk.name])) + def result_list(cl): """ Displays the headers and data list together """ return {'cl': cl, + 'result_hidden_fields': list(result_hidden_fields(cl)), 'result_headers': list(result_headers(cl)), 'results': list(results(cl))} result_list = register.inclusion_tag("admin/change_list_results.html")(result_list) diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py index b70d7c51f4..c8ad1ce8f6 100644 --- a/tests/regressiontests/admin_changelist/tests.py +++ b/tests/regressiontests/admin_changelist/tests.py @@ -1,10 +1,10 @@ -import unittest from django.contrib import admin from django.contrib.admin.views.main import ChangeList from django.template import Context, Template +from django.test import TransactionTestCase from regressiontests.admin_changelist.models import Child, Parent -class ChangeListTests(unittest.TestCase): +class ChangeListTests(TransactionTestCase): def test_select_related_preserved(self): """ Regression test for #10348: ChangeList.get_query_set() shouldn't @@ -18,9 +18,8 @@ class ChangeListTests(unittest.TestCase): def test_result_list_html(self): """ - Regression test for #11791: Inclusion tag result_list generates a - table and this checks that the items are nested within the table - element tags. + Verifies that inclusion tag result_list generates a table when with + default ModelAdmin settings. """ new_parent = Parent.objects.create(name='parent') new_child = Child.objects.create(name='name', parent=new_parent) @@ -29,16 +28,27 @@ class ChangeListTests(unittest.TestCase): cl = ChangeList(request, Child, m.list_display, m.list_display_links, m.list_filter, m.date_hierarchy, m.search_fields, m.list_select_related, m.list_per_page, m.list_editable, m) - FormSet = m.get_changelist_formset(request) - cl.formset = FormSet(queryset=cl.result_list) + cl.formset = None template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') context = Context({'cl': cl}) table_output = template.render(context) - hidden_input_elem = '' - self.failIf(table_output.find(hidden_input_elem) == -1, - 'Failed to find expected hidden input element in: %s' % table_output) - self.failIf(table_output.find('%s | ' % hidden_input_elem) == -1, - 'Hidden input element is not enclosed inelement.') + row_html = ' |
name | Parent object | %s | ' % hidden_input_elem) == -1, - 'Hidden input element is not enclosed inelement.') + # make sure that hidden fields are in the correct place + hiddenfields_div = '' + self.failIf(table_output.find(hiddenfields_div) == -1, + 'Failed to find hidden fields in: %s' % table_output) + # make sure that list editable fields are rendered in divs correctly + editable_name_field = '' + self.failIf(' | %s | ' % editable_name_field == -1, + 'Failed to find "name" list_editable field in: %s' % table_output) class ChildAdmin(admin.ModelAdmin): list_display = ['name', 'parent']
---|