Opened 5 years ago

Closed 5 years ago

#17515 closed New feature (fixed)

custom templates in FilterSpec

Reported by: Stefano Apostolico Owned by: Stefano Apostolico
Component: contrib.admin Version: master
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 5 years ago.
filterspec_custom_templates_0.1.diff (5.4 KB) - added by Stefano Apostolico 5 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 5 years ago.

Download all attachments as: .zip

Change History (11)

Changed 5 years ago by Stefano Apostolico

comment:1 Changed 5 years ago by Julien Phalip

Needs documentation: set
Needs tests: set
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by Stefano Apostolico

Owner: changed from nobody to Stefano Apostolico
Status: newassigned

comment:3 Changed 5 years ago by Stefano Apostolico

Needs documentation: unset
Needs tests: unset

renamed attribute template as template_name

Last edited 5 years ago by Stefano Apostolico (previous) (diff)

Changed 5 years ago by Stefano Apostolico

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

comment:4 Changed 5 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:5 Changed 5 years ago by Julien Phalip

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.

Changed 5 years ago by Julien Phalip

comment:6 Changed 5 years ago by Julien Phalip

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 Changed 5 years ago by Julien Phalip

Patch needs improvement: unset

comment:8 Changed 5 years ago by Jannis Leidel

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