diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index ba3d132..a9db7aa 100644
a
|
b
|
def items_for_result(cl, result, form):
|
170 | 170 | first = True |
171 | 171 | pk = cl.lookup_opts.pk.attname |
172 | 172 | for field_name in cl.list_display: |
173 | | row_class = '' |
| 173 | row_classes = ['field-%s' % field_name] |
174 | 174 | try: |
175 | 175 | f, attr, value = lookup_field(field_name, result, cl.model_admin) |
176 | 176 | except (AttributeError, ObjectDoesNotExist): |
… |
… |
def items_for_result(cl, result, form):
|
178 | 178 | else: |
179 | 179 | if f is None: |
180 | 180 | if field_name == u'action_checkbox': |
181 | | row_class = ' class="action-checkbox"' |
| 181 | row_classes = ['action-checkbox'] |
182 | 182 | allow_tags = getattr(attr, 'allow_tags', False) |
183 | 183 | boolean = getattr(attr, 'boolean', False) |
184 | 184 | if boolean: |
… |
… |
def items_for_result(cl, result, form):
|
204 | 204 | if isinstance(f, models.DateField)\ |
205 | 205 | or isinstance(f, models.TimeField)\ |
206 | 206 | or isinstance(f, models.ForeignKey): |
207 | | row_class = ' class="nowrap"' |
| 207 | row_classes.append('nowrap') |
208 | 208 | if force_unicode(result_repr) == '': |
209 | 209 | result_repr = mark_safe(' ') |
| 210 | row_class = ' class="%s"' % ' '.join(row_classes) |
210 | 211 | # If list_display_links not defined, add the link tag to the first field |
211 | 212 | if (first and not cl.list_display_links) or field_name in cl.list_display_links: |
212 | 213 | table_tag = {True:'th', False:'td'}[first] |
diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
index 9347dbf..27a7cc4 100644
a
|
b
|
class ChangeListTests(TestCase):
|
49 | 49 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
50 | 50 | context = Context({'cl': cl}) |
51 | 51 | table_output = template.render(context) |
52 | | 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) |
| 52 | row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th class="field-name"><a href="%d/">name</a></th><td class="field-parent nowrap">(None)</td></tr></tbody>' % (new_child.id, new_child.id) |
53 | 53 | self.assertFalse(table_output.find(row_html) == -1, |
54 | 54 | 'Failed to find expected row element: %s' % table_output) |
55 | 55 | |
… |
… |
class ChangeListTests(TestCase):
|
69 | 69 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
70 | 70 | context = Context({'cl': cl}) |
71 | 71 | table_output = template.render(context) |
72 | | 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) |
| 72 | row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th class="field-name"><a href="%d/">name</a></th><td class="field-parent nowrap">Parent object</td></tr></tbody>' % (new_child.id, new_child.id) |
73 | 73 | self.assertFalse(table_output.find(row_html) == -1, |
74 | 74 | 'Failed to find expected row element: %s' % table_output) |
75 | 75 | |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index b6e7b9e..ceda533 100644
a
|
b
|
class AdminViewDeletedObjectsTest(TestCase):
|
1180 | 1180 | response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3)) |
1181 | 1181 | self.assertContains(response, should_contain) |
1182 | 1182 | |
| 1183 | class AdminChangeListCSSClassesTest(TestCase): |
| 1184 | urls = "regressiontests.admin_views.urls" |
| 1185 | fixtures = ['admin-views-users.xml'] |
| 1186 | |
| 1187 | def setUp(self): |
| 1188 | self.client.login(username='super', password='secret') |
| 1189 | |
| 1190 | def tearDown(self): |
| 1191 | self.client.logout() |
| 1192 | |
| 1193 | def test_class_attributes(self): |
| 1194 | """ |
| 1195 | Cells of the change list table should contain the field name in their class attribute |
| 1196 | Refs #11195. |
| 1197 | """ |
| 1198 | Podcast.objects.create(name="Django Dose", |
| 1199 | release_date=datetime.date.today()) |
| 1200 | response = self.client.get('/test_admin/admin/admin_views/podcast/') |
| 1201 | self.assertContains( |
| 1202 | response, '<th class="field-name">') |
| 1203 | self.assertContains( |
| 1204 | response, '<td class="field-release_date nowrap">') |
| 1205 | self.assertContains( |
| 1206 | response, '<td class="action-checkbox">') |
| 1207 | |
1183 | 1208 | class AdminViewStringPrimaryKeyTest(TestCase): |
1184 | 1209 | urls = "regressiontests.admin_views.urls" |
1185 | 1210 | fixtures = ['admin-views-users.xml', 'string-primary-key.xml'] |
… |
… |
class AdminViewStringPrimaryKeyTest(TestCase):
|
1211 | 1236 | def test_changelist_to_changeform_link(self): |
1212 | 1237 | "The link from the changelist referring to the changeform of the object should be quoted" |
1213 | 1238 | response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/') |
1214 | | should_contain = """<th><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk)) |
| 1239 | should_contain = """<th class="field-__str__"><a href="%s/">%s</a></th></tr>""" % (quote(self.pk), escape(self.pk)) |
1215 | 1240 | self.assertContains(response, should_contain) |
1216 | 1241 | |
1217 | 1242 | def test_recentactions_link(self): |
… |
… |
class AdminViewListEditable(TestCase):
|
1823 | 1848 | self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. |
1824 | 1849 | self.assertContains(response, 'id="id_form-1-id"', 1) |
1825 | 1850 | 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)) |
1826 | | self.assertContains(response, '<td>%d</td>' % story1.id, 1) |
1827 | | self.assertContains(response, '<td>%d</td>' % story2.id, 1) |
| 1851 | self.assertContains(response, '<td class="field-id">%d</td>' % story1.id, 1) |
| 1852 | self.assertContains(response, '<td class="field-id">%d</td>' % story2.id, 1) |
1828 | 1853 | |
1829 | 1854 | def test_pk_hidden_fields_with_list_display_links(self): |
1830 | 1855 | """ Similarly as test_pk_hidden_fields, but when the hidden pk fields are |
… |
… |
class AdminViewListEditable(TestCase):
|
1837 | 1862 | self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. |
1838 | 1863 | self.assertContains(response, 'id="id_form-1-id"', 1) |
1839 | 1864 | 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)) |
1840 | | self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1) |
1841 | | self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1) |
| 1865 | self.assertContains(response, '<th class="field-id"><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1) |
| 1866 | self.assertContains(response, '<th class="field-id"><a href="%d/">%d</a></th>' % (story2.id, story2.id), 1) |
1842 | 1867 | |
1843 | 1868 | |
1844 | 1869 | class AdminSearchTest(TestCase): |