Opened 13 years ago

Closed 13 years ago

#17515 closed New feature (fixed)

custom templates in FilterSpec

Reported by: Stefano Apostolico Owned by: Stefano Apostolico
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

django 1.4 allow an easier customization of FilterSpec but force all to the same presentation, should be useful customize the template used by the filter.
The patch simply allow to specify the template to use into FilterSpec or use the default one otherwise, moreover put the FilterSpec into the context to be available into temlplate

def admin_list_filter(cl, spec):
    if hasattr(spec, 'template') and spec.template:
        t = get_template(spec.template)
    else:
        t = get_template('admin/filter.html')
    ctx = Context({'title': spec.title, 'choices' : list(spec.choices(cl)), 'spec': spec})
    return t.render(ctx)

Attachments (3)

filterspec_custom_templates.diff (1.1 KB ) - added by Stefano Apostolico 13 years ago.
filterspec_custom_templates_0.1.diff (5.4 KB ) - added by Stefano Apostolico 13 years ago.
patch with docs and tests also renamed template attribute as 'template_name'
17515.admin-filter-custom-templates.diff (6.6 KB ) - added by Julien Phalip 13 years ago.

Download all attachments as: .zip

Change History (11)

by Stefano Apostolico, 13 years ago

comment:1 by Julien Phalip, 13 years ago

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:2 by Stefano Apostolico, 13 years ago

Owner: changed from nobody to Stefano Apostolico
Status: newassigned

comment:3 by Stefano Apostolico, 13 years ago

Needs documentation: unset
Needs tests: unset
Version 0, edited 13 years ago by Stefano Apostolico (next)

by Stefano Apostolico, 13 years ago

patch with docs and tests also renamed template attribute as 'template_name'

comment:4 by Jannis Leidel, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Julien Phalip, 13 years ago

Patch needs improvement: set

I think that 'template' would be better than 'template_name' and more consistent with other similar attributes in the admin (e.g. StackedInline.template or ModelAdmin.change_form_template). Also, a custom template file actually needs to be included in the patch.

by Julien Phalip, 13 years ago

comment:6 by Julien Phalip, 13 years ago

The latest patch uses 'template' instead of 'template_name', cleans up the implementation a bit and adds a custom template file to the tests.

comment:7 by Julien Phalip, 13 years ago

Patch needs improvement: unset

comment:8 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: assignedclosed

In [17483]:

Fixed #17515 -- Added ability to override the template of custom admin FilterSpec classes. Thanks, saxix and Julien Phalip.

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