Opened 5 years ago

Last modified 4 years ago

#12566 assigned New feature

admin action templates cannot be overriden on a per-app basis

Reported by: bjj Owned by: rctay
Component: contrib.admin Version: 1.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

For example, if you want to customize the 'actions' dropdown menu you might think you could copy in actions.html and modify it. However, it is rendered in change_list.html by calling the admin_actions templatetag. Those templatetags use register.inclusion_tag which does not search for application- or model-specific versions of a template.

You can't even work around it by overriding callers like change_list.html without also overriding the templatetag (copying it and changing the template name).

Attachments (5)

0001-contrib.admin-refactor-updating-of-action_index-to-n.patch (3.8 KB) - added by rctay 5 years ago.
contrib.admin: refactor updating of action_index to not use inclusion tag
0000-admin-change_list.html-strip-trailing-whitespace.patch (1.2 KB) - added by rctay 5 years ago.
admin/change_list.html: strip trailing whitespace
0003-ref-contrib-admin-index-document-action_template.patch (1.8 KB) - added by rctay 5 years ago.
ref/contrib/admin/index: document action_template
0002-contrib.admin-allow-overriding-of-action-template-at.patch (3.8 KB) - added by rctay 5 years ago.
contrib.admin: allow overriding of action template at app-level
0001-contrib.admin-allow-overriding-of-actions.html-templ.patch (11.0 KB) - added by rctay 5 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 5 years ago by russellm

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

Changed 5 years ago by rctay

contrib.admin: refactor updating of action_index to not use inclusion tag

comment:2 follow-up: Changed 5 years ago by rctay

  • Has patch set
  • Owner changed from nobody to rctay
  • Status changed from new to assigned

I have separated my fix into two parts:

  1. http://code.djangoproject.com/attachment/ticket/12566/0001-contrib.admin-refactor-updating-of-action_index-to-n.patch Part 1: The only reason for the template tag {%admin_action%} was to update the variable action_index in the context. The patch replaces it with a tag {% get_action_index %} to just spit out a value to be used as the action index, without template inclusion. The action template admin/actions.html is now included manually via {% include %} in admin/change_list.html.
  1. http://code.djangoproject.com/attachment/ticket/12566/0002-contrib.admin-allow-overriding-of-action-template-at.patch Part 2: Add some code to change_view select which template to use for the action form. I followed the style of template selection (eg. self.<thing>_template, followed by admin/mod/obj/<thing>.html, followed by...) from what we are already doing, eg. for change list, change form.

comment:3 in reply to: ↑ 2 Changed 5 years ago by rctay

Replying to rctay:

  1. http://code.djangoproject.com/attachment/ticket/12566/0001-contrib.admin-refactor-updating-of-action_index-to-n.patch Part 1: The only reason for the template tag {%admin_action%}

I meant "The only reason for...to be around".

comment:4 Changed 5 years ago by rctay

  • Summary changed from Admin templates rendered from templatetags cannot be overridden by applications to admin action templates cannot be overriden on a per-app basis

Changed 5 years ago by rctay

admin/change_list.html: strip trailing whitespace

Changed 5 years ago by rctay

ref/contrib/admin/index: document action_template

Changed 5 years ago by rctay

contrib.admin: allow overriding of action template at app-level

comment:5 Changed 5 years ago by rctay

Replaced patch so that app-level overriding of templates work.

comment:6 Changed 5 years ago by rctay

  • Triage Stage changed from Accepted to Ready for checkin

Please pardon me if the status is inappropriate; it's my first time advancing a ticket's triage stage.

comment:7 Changed 5 years ago by ramiro

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

Ideally, ticket stage field changes to accepted or ready for checkin shouldn't be performed by patch submitter and/or ticket reporter. Review by another pair of eyes is preferred, see http://docs.djangoproject.com/en/1.1/internals/contributing/#triage-by-the-general-community

Also, please merge all the patches in one file.

comment:8 Changed 5 years ago by rctay

  • Needs tests unset
  • Patch needs improvement unset

comment:9 Changed 5 years ago by rctay

Removed stray print.

comment:10 Changed 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to New feature

comment:11 Changed 4 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

0001-contrib.admin-allow-overriding-of-actions.html-templ.patch fails to apply cleanly on to trunk

comment:12 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

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