Opened 17 years ago

Closed 14 years ago

#6636 closed (fixed)

change_form.html template should have a block around fieldsets

Reported by: peschler Owned by: nobody
Component: contrib.admin Version: 1.3
Severity: Keywords: newforms admin template nfa-someday
Cc: Julie Pichon Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

6636.diff (1009 bytes ) - added by Julie Pichon 14 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Karen Tracey <kmtracey@…>, 17 years ago

Keywords: nfa-someday added

Stated in description this applies to both trunk and nfa, should not block nfa merge.

comment:2 by edgarsj, 17 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Julie Pichon, 14 years ago

Cc: Julie Pichon added

Is there something preventing this patch from being applied? I'm attaching a diff of peschler's patch against the latest change_form.html in trunk so it can be applied more easily. I also added a block to inline fieldsets, for the same reasons than in the initial report. Let me know if there's something else I can do to help with this?

by Julie Pichon, 14 years ago

Attachment: 6636.diff added

comment:4 by Russell Keith-Magee, 14 years ago

Triage Stage: AcceptedReady for checkin
Version: newforms-admin1.3

The only thing holding up this ticket is the fact that nobody has ever reviewed it and marked it ready for checkin. It's a simple fix, so I'll do that now.

comment:5 by Adrian Holovaty, 14 years ago

Resolution: fixed
Status: newclosed

In [15925]:

Fixed #6636 -- Added template blocks to admin change_form.html template for fieldsets and inline fieldsets. Thanks, peschler and jpichon

Note: See TracTickets for help on using tickets.
Back to Top