| 19 | def test_result_list_html(self): |
| 20 | """ |
| 21 | Regression test for #11791: Inclusion tag result_list generates a |
| 22 | table and this checks that the items are nested within the table |
| 23 | element tags. |
| 24 | """ |
| 25 | new_parent = Parent.objects.create(name='parent') |
| 26 | new_child = Child.objects.create(name='name', parent=new_parent) |
| 27 | request = MockRequest() |
| 28 | m = ChildAdmin(Child, admin.site) |
| 29 | cl = ChangeList(request, Child, m.list_display, m.list_display_links, |
| 30 | m.list_filter,m.date_hierarchy, m.search_fields, |
| 31 | m.list_select_related, m.list_per_page, m.list_editable, m) |
| 32 | FormSet = m.get_changelist_formset(request) |
| 33 | cl.formset = FormSet(queryset=cl.result_list) |
| 34 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
| 35 | context = Context({'cl': cl}) |
| 36 | table_output = template.render(context) |
| 37 | self.assertEqual(table_output, u'<table cellspacing="0"><thead><tr><th class="action-checkbox-column"><input type="checkbox" id="action-toggle" /></th><th><a href="?ot=asc&o=1">\nName\n</a></th><th><a href="?ot=asc&o=2">\nParent\n</a></th></tr></thead><tbody><tr class="row1"><td><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td>Parent object</td><td><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></td></tr></tbody></table>') |
| 38 | |
| 39 | # Test with list_editable fields |
| 40 | m.list_display = ['id', 'name', 'parent'] |
| 41 | m.list_display_links = ['id'] |
| 42 | m.list_editable = ['name'] |
| 43 | cl = ChangeList(request, Child, m.list_display, m.list_display_links, |
| 44 | m.list_filter,m.date_hierarchy, m.search_fields, |
| 45 | m.list_select_related, m.list_per_page, m.list_editable, m) |
| 46 | FormSet = m.get_changelist_formset(request) |
| 47 | cl.formset = FormSet(queryset=cl.result_list) |
| 48 | template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') |
| 49 | context = Context({'cl': cl}) |
| 50 | table_output = template.render(context) |
| 51 | self.assertEqual(table_output, u'<table cellspacing="0"><thead><tr><th class="sorted descending"><a href="?ot=asc&o=0">\nID\n</a></th><th><a href="?ot=asc&o=1">\nName\n</a></th><th><a href="?ot=asc&o=2">\nParent\n</a></th></tr></thead><tbody><tr class="row1"><th><a href="1/">1</a></th><td><input name="form-0-name" value="name" class="vTextField" maxlength="30" type="text" id="id_form-0-name" /></td><td>Parent object</td><td><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></td></tr></tbody></table>') |
| 52 | |