Code

Opened 2 years ago

Closed 2 years ago

#17515 closed New feature (fixed)

custom templates in FilterSpec

Reported by: saxix Owned by: saxix
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 saxix 2 years ago.
filterspec_custom_templates_0.1.diff (5.4 KB) - added by saxix 2 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 2 years ago.

Download all attachments as: .zip

Change History (11)

Changed 2 years ago by saxix

comment:1 Changed 2 years ago by julien

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 years ago by saxix

  • Owner changed from nobody to saxix
  • Status changed from new to assigned

comment:3 Changed 2 years ago by saxix

  • Needs documentation unset
  • Needs tests unset

renamed attribute template as template_name

Last edited 2 years ago by saxix (previous) (diff)

Changed 2 years ago by saxix

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

comment:4 Changed 2 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 2 years ago by julien

  • 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 2 years ago by julien

comment:6 Changed 2 years ago by julien

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 2 years ago by julien

  • Patch needs improvement unset

comment:8 Changed 2 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

In [17483]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.