Ticket #13599: separate_hidden_fields.patch

File separate_hidden_fields.patch, 3.1 KB (added by magnus, 5 years ago)

A patch with the hidden inputs placed above the results table

  • django/contrib/admin/templates/admin/change_list_results.html

     
     1{% if result_hidden_fields %}
     2<div style="display: none"> {# DIV for HTML validation #}
     3{% for item in result_hidden_fields %}{{ item }}{% endfor %}
     4</div>
     5{% endif %}
    16{% if results %}
    27<table cellspacing="0" id="result_list">
    38<thead>
  • django/contrib/admin/templatetags/admin_list.py

     
    189189            else:
    190190                result_repr = conditional_escape(result_repr)
    191191            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:
    193193        yield mark_safe(u'<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name]))
    194194
    195195def results(cl):
     
    200200        for res in cl.result_list:
    201201            yield list(items_for_result(cl, res, None))
    202202
     203def 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
    203209def result_list(cl):
    204210    """
    205211    Displays the headers and data list together
    206212    """
    207213    return {'cl': cl,
     214            'result_hidden_fields': list(result_hidden_fields(cl)),
    208215            'result_headers': list(result_headers(cl)),
    209216            'results': list(results(cl))}
    210217result_list = register.inclusion_tag("admin/change_list_results.html")(result_list)
  • tests/regressiontests/admin_changelist/tests.py

     
    3737        hidden_input_elem = '<input type="hidden" name="form-0-id" value="1" id="id_form-0-id" />'
    3838        self.failIf(table_output.find(hidden_input_elem) == -1,
    3939            '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.')
    4240
    4341        # Test with list_editable fields
    4442        m.list_display = ['id', 'name', 'parent']
     
    5452        table_output = template.render(context)
    5553        self.failIf(table_output.find(hidden_input_elem) == -1,
    5654            '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.')
    5955
    6056class ChildAdmin(admin.ModelAdmin):
    6157    list_display = ['name', 'parent']
Back to Top