diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index b72c0be..e068cd6 100644
a
|
b
|
def items_for_result(cl, result, form):
|
133 | 133 | first = True |
134 | 134 | pk = cl.lookup_opts.pk.attname |
135 | 135 | for field_name in cl.list_display: |
136 | | row_class = '' |
| 136 | row_classes = ['%s-cell' % field_name] |
137 | 137 | try: |
138 | 138 | f, attr, value = lookup_field(field_name, result, cl.model_admin) |
139 | 139 | except (AttributeError, ObjectDoesNotExist): |
… |
… |
def items_for_result(cl, result, form):
|
141 | 141 | else: |
142 | 142 | if f is None: |
143 | 143 | if field_name == u'action_checkbox': |
144 | | row_class = ' class="action-checkbox"' |
| 144 | row_classes = ['action-checkbox'] |
145 | 145 | allow_tags = getattr(attr, 'allow_tags', False) |
146 | 146 | boolean = getattr(attr, 'boolean', False) |
147 | 147 | if boolean: |
… |
… |
def items_for_result(cl, result, form):
|
167 | 167 | if isinstance(f, models.DateField)\ |
168 | 168 | or isinstance(f, models.TimeField)\ |
169 | 169 | or isinstance(f, models.ForeignKey): |
170 | | row_class = ' class="nowrap"' |
| 170 | row_classes.append('nowrap') |
171 | 171 | if force_unicode(result_repr) == '': |
172 | 172 | result_repr = mark_safe(' ') |
| 173 | row_class = ' class="%s"' % ' '.join(row_classes) |
173 | 174 | # If list_display_links not defined, add the link tag to the first field |
174 | 175 | if (first and not cl.list_display_links) or field_name in cl.list_display_links: |
175 | 176 | table_tag = {True:'th', False:'td'}[first] |
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index 5186508..782f91a 100644
a
|
b
|
class ChangeListTests(TransactionTestCase):
|
36 | 36 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
37 | 37 | context = Context({'cl': cl}) |
38 | 38 | table_output = template.render(context) |
39 | | 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) |
| 39 | row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th class="name-cell"><a href="%d/">name</a></th><td class="parent-cell nowrap">(None)</td></tr></tbody>' % (new_child.id, new_child.id) |
40 | 40 | self.assertFalse(table_output.find(row_html) == -1, |
41 | 41 | 'Failed to find expected row element: %s' % table_output) |
42 | 42 | |
… |
… |
class ChangeListTests(TransactionTestCase):
|
57 | 57 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
58 | 58 | context = Context({'cl': cl}) |
59 | 59 | table_output = template.render(context) |
60 | | 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) |
| 60 | row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th class="name-cell"><a href="%d/">name</a></th><td class="parent-cell nowrap">Parent object</td></tr></tbody>' % (new_child.id, new_child.id) |
61 | 61 | self.assertFalse(table_output.find(row_html) == -1, |
62 | 62 | 'Failed to find expected row element: %s' % table_output) |
63 | 63 | |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 54d89e4..c9a5bd1 100644
a
|
b
|
class AdminViewDeletedObjectsTest(TestCase):
|
1052 | 1052 | response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3)) |
1053 | 1053 | self.assertContains(response, should_contain) |
1054 | 1054 | |
| 1055 | class AdminChangeListCSSClassesTest(TestCase): |
| 1056 | fixtures = ['admin-views-users.xml'] |
| 1057 | |
| 1058 | def setUp(self): |
| 1059 | self.client.login(username='super', password='secret') |
| 1060 | |
| 1061 | def tearDown(self): |
| 1062 | self.client.logout() |
| 1063 | |
| 1064 | def test_class_attributes(self): |
| 1065 | """ |
| 1066 | Cells of the change list table should contain the field name in their class attribute |
| 1067 | Refs #11195. |
| 1068 | """ |
| 1069 | Podcast.objects.create(name="Django Dose", |
| 1070 | release_date=datetime.date.today()) |
| 1071 | response = self.client.get('/test_admin/admin/admin_views/podcast/') |
| 1072 | self.assertContains( |
| 1073 | response, '<th class="name-cell">') |
| 1074 | self.assertContains( |
| 1075 | response, '<td class="release_date-cell nowrap">') |
| 1076 | self.assertContains( |
| 1077 | response, '<td class="action-checkbox">') |
| 1078 | |
1055 | 1079 | class AdminViewStringPrimaryKeyTest(TestCase): |
1056 | 1080 | fixtures = ['admin-views-users.xml', 'string-primary-key.xml'] |
1057 | 1081 | |
… |
… |
class AdminViewStringPrimaryKeyTest(TestCase):
|
1082 | 1106 | def test_changelist_to_changeform_link(self): |
1083 | 1107 | "The link from the changelist referring to the changeform of the object should be quoted" |
1084 | 1108 | response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/') |
1085 | | should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk)) |
| 1109 | should_contain = """<th class="__str__-cell"><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk)) |
1086 | 1110 | self.assertContains(response, should_contain) |
1087 | 1111 | |
1088 | 1112 | def test_recentactions_link(self): |
… |
… |
class AdminViewListEditable(TestCase):
|
1691 | 1715 | self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. |
1692 | 1716 | self.assertContains(response, 'id="id_form-1-id"', 1) |
1693 | 1717 | self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id)) |
1694 | | self.assertContains(response, '<td>%d</td>' % story1.id, 1) |
1695 | | self.assertContains(response, '<td>%d</td>' % story2.id, 1) |
| 1718 | self.assertContains(response, '<td class="id-cell">%d</td>' % story1.id, 1) |
| 1719 | self.assertContains(response, '<td class="id-cell">%d</td>' % story2.id, 1) |
1696 | 1720 | |
1697 | 1721 | def test_pk_hidden_fields_with_list_display_links(self): |
1698 | 1722 | """ Similarly as test_pk_hidden_fields, but when the hidden pk fields are |
… |
… |
class AdminViewListEditable(TestCase):
|
1705 | 1729 | self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. |
1706 | 1730 | self.assertContains(response, 'id="id_form-1-id"', 1) |
1707 | 1731 | self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id)) |
1708 | | self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1) |
1709 | | self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1) |
| 1732 | self.assertContains(response, '<th class="id-cell"><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1) |
| 1733 | self.assertContains(response, '<th class="id-cell"><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1) |
1710 | 1734 | |
1711 | 1735 | |
1712 | 1736 | class AdminSearchTest(TestCase): |