﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6636	change_form.html template should have a block around fieldsets	peschler	nobody	"The default admin/changeform_html should be more granular concerning blocks or at least contain a block around the fieldsets to prevent code duplication. This applies to trunk and the newform-admin branch.

Here's a more elaborate explanation of the problem:

The ``admin/change_form.html`` template of the newforms-admin branch offers a variety of blocks to override. Unfortunately the main content block contains some areas which cannot be overwritten without duplicating a lot of code. Basically the block structure in the original newforms-admin change_form.html looks like this.

{{{
    {% block content %}        
        {% block object-tools %}some tools here...{% endblock object-tools %}

        # code for fieldsets (without block!)
        
        {% block after_field_sets %}{% endblock %}

        {% for inline_admin_formset in inline_admin_formsets %}
            {% include inline_admin_formset.opts.template %}
        {% endfor %}

        {% block after_related_objects %}{% endblock %}        
    {% endblock content %}
}}}

As you can see there are some blocks for adding stuff behind the fieldsets and the related objects (blocks ``after_field_sets`` and
``after_related_objects``) but unfortunately there is no way to overwrite the fieldsets because they are not contained within any block.

So why deal with that? If you want to overwrite the fieldset stuff in the above template, you *must* overwrite the ``content`` block. Thereby you loose all blocks within the ``content`` block (is this a bug or a feature?!) And that simply means you cannot do this:

{{{
    {% block content %}
        My new content!
        
        {% block object-tools %}
            {{ block.super }}           # does not work!
        {% endblock object-tools %}

        My new field stuff here...
        ...
    {% endblock content %}
}}}

This snippet tries to add some content before and after the object tools and
at the same time reuse the ``object-tools`` block from the parent template by
calling ``block.super``. But that fails and the ``object_tools`` block will be
empty as will all child blocks of ``content``. Thus the only choice is to
duplicate the *whole* ``content`` code, which is not DRY.

We can workaround this problem by restructuring the original
``change_form.html`` and putting the fieldsets into their own block like
this::

{{{
    {% block content %}        
        {% block object-tools %}some tools here...{% endblock object-tools %}
        
        {% block field_sets %}
            # code for fieldsets (this time with block)
        {% endblock %}

        {% block after_field_sets %}{% endblock %}

        {% for inline_admin_formset in inline_admin_formsets %}
            {% include inline_admin_formset.opts.template %}
        {% endfor %}

        {% block after_related_objects %}{% endblock %}
{% endblock content %}
}}}

By making the template more granular, we can now simply overwrite the ``field_sets``
block instead of the ``content`` block and all other blocks within
``content`` stay intact.
"		closed	contrib.admin	1.3		fixed	newforms admin template nfa-someday	Julie Pichon	Ready for checkin	1	0	0	0	0	0
