Ticket #11791: result_list.diff

File result_list.diff, 4.2 KB (added by Mark Lavin, 15 years ago)

Patch with tests for modified 'result_list' inclusion tag

  • django/contrib/admin/templatetags/admin_list.py

     
    242242                result_repr = conditional_escape(result_repr)
    243243            yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr))
    244244    if form:
    245         yield mark_safe(force_unicode(form[cl.model._meta.pk.name]))
     245        yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name]))
    246246
    247247def results(cl):
    248248    if cl.formset:
  • tests/regressiontests/admin_changelist/tests.py

     
    11import unittest
    22from django.contrib import admin
    33from django.contrib.admin.views.main import ChangeList
    4 from regressiontests.admin_changelist.models import Child
     4from django.template import Context, Template
     5from regressiontests.admin_changelist.models import Child, Parent
    56
    67class ChangeListTests(unittest.TestCase):
    78    def test_select_related_preserved(self):
     
    1516                m.list_select_related, m.list_per_page, m.list_editable, m)
    1617        self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}})
    1718
     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&amp;o=1">\nName\n</a></th><th><a href="?ot=asc&amp;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&amp;o=0">\nID\n</a></th><th><a href="?ot=asc&amp;o=1">\nName\n</a></th><th><a href="?ot=asc&amp;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
    1853class ChildAdmin(admin.ModelAdmin):
    1954    list_display = ['name', 'parent']
    2055    def queryset(self, request):
Back to Top