Ticket #13599: seperate_hidden_fields.patch
File seperate_hidden_fields.patch, 6.8 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/media/css/changelists.css
9 9 width: 100%; 10 10 } 11 11 12 .change-list .hiddenfields { display:none; } 13 12 14 .change-list .filtered table { 13 15 border-right: 1px solid #ddd; 14 16 } -
django/contrib/admin/templatetags/admin_list.py
189 189 else: 190 190 result_repr = conditional_escape(result_repr) 191 191 yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr)) 192 if form :192 if form and not form[cl.model._meta.pk.name].is_hidden: 193 193 yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name])) 194 194 195 195 def results(cl): … … 200 200 for res in cl.result_list: 201 201 yield list(items_for_result(cl, res, None)) 202 202 203 def result_hidden_fields(cl): 204 if cl.formset: 205 for res, form in zip(cl.result_list, cl.formset.forms): 206 if form[cl.model._meta.pk.name].is_hidden: 207 yield mark_safe(force_unicode(form[cl.model._meta.pk.name])) 208 203 209 def result_list(cl): 204 210 """ 205 211 Displays the headers and data list together 206 212 """ 207 213 return {'cl': cl, 214 'result_hidden_fields': list(result_hidden_fields(cl)), 208 215 'result_headers': list(result_headers(cl)), 209 216 'results': list(results(cl))} 210 217 result_list = register.inclusion_tag("admin/change_list_results.html")(result_list) -
django/contrib/admin/templates/admin/change_list_results.html
1 {% if result_hidden_fields %} 2 <div class="hiddenfields"> {# DIV for HTML validation #} 3 {% for item in result_hidden_fields %}{{ item }}{% endfor %} 4 </div> 5 {% endif %} 1 6 {% if results %} 2 7 <div class="results"> 3 8 <table cellspacing="0" id="result_list"> -
tests/regressiontests/admin_changelist/tests.py
1 import unittest2 1 from django.contrib import admin 3 2 from django.contrib.admin.views.main import ChangeList 4 3 from django.template import Context, Template 4 from django.test import TransactionTestCase 5 5 from regressiontests.admin_changelist.models import Child, Parent 6 6 7 class ChangeListTests( unittest.TestCase):7 class ChangeListTests(TransactionTestCase): 8 8 def test_select_related_preserved(self): 9 9 """ 10 10 Regression test for #10348: ChangeList.get_query_set() shouldn't … … 17 17 self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}}) 18 18 19 19 def test_result_list_html(self): 20 """21 Regression test for #11791: Inclusion tag result_list generates a22 table and this checks that the items are nested within the table23 element tags.24 """25 20 new_parent = Parent.objects.create(name='parent') 26 21 new_child = Child.objects.create(name='name', parent=new_parent) 27 22 request = MockRequest() … … 29 24 cl = ChangeList(request, Child, m.list_display, m.list_display_links, 30 25 m.list_filter, m.date_hierarchy, m.search_fields, 31 26 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) 27 cl.formset = None 34 28 template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') 35 29 context = Context({'cl': cl}) 36 30 table_output = template.render(context) 37 hidden_input_elem = '<input type="hidden" name="form-0-id" value="1" id="id_form-0-id" />' 38 self.failIf(table_output.find(hidden_input_elem) == -1, 39 'Failed to find expected hidden input element in: %s' % table_output) 40 self.failIf(table_output.find('<td>%s</td>' % hidden_input_elem) == -1, 41 'Hidden input element is not enclosed in <td> element.') 31 row_html = '<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></tr></tbody>' 32 self.failIf(table_output.find(row_html) == -1, 33 'Failed to find expected row element: %s' % table_output) 42 34 35 def test_result_list_editable_html(self): 36 """ 37 Regression test for #11791: Inclusion tag result_list generates a 38 table and this checks that the items are nested within the table 39 element tags. Also tests #13599, and verifies that hidden fields 40 when list_editable is enabled are rendered in a div outside the 41 table. 42 """ 43 new_parent = Parent.objects.create(name='parent') 44 new_child = Child.objects.create(name='name', parent=new_parent) 45 request = MockRequest() 46 m = ChildAdmin(Child, admin.site) 47 43 48 # Test with list_editable fields 44 49 m.list_display = ['id', 'name', 'parent'] 45 50 m.list_display_links = ['id'] … … 52 57 template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') 53 58 context = Context({'cl': cl}) 54 59 table_output = template.render(context) 55 self.failIf(table_output.find(hidden_input_elem) == -1, 56 'Failed to find expected hidden input element in: %s' % table_output) 57 self.failIf(table_output.find('<td>%s</td>' % hidden_input_elem) == -1, 58 'Hidden input element is not enclosed in <td> element.') 60 # make sure that hidden fields are in the correct place 61 hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>' 62 self.failIf(table_output.find(hiddenfields_div) == -1, 63 'Failed to find hidden fields in: %s' % table_output) 64 # make sure that list editable fields are rendered in divs correctly 65 editable_name_field = '<input name="form-0-name" value="name" class="vTextField" maxlength="30" type="text" id="id_form-0-name" />' 66 self.failIf('<td>%s</td>' % editable_name_field == -1, 67 'Failed to find "name" list_editable field in: %s' % table_output) 59 68 60 69 class ChildAdmin(admin.ModelAdmin): 61 70 list_display = ['name', 'parent']