Opened 7 years ago

Last modified 6 years ago

#12566 assigned New feature

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

Reported by: Ben Jackson Owned by: Tay Ray Chuan
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 Tay Ray Chuan 7 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 Tay Ray Chuan 7 years ago.
admin/change_list.html: strip trailing whitespace
0003-ref-contrib-admin-index-document-action_template.patch (1.8 KB) - added by Tay Ray Chuan 7 years ago.
ref/contrib/admin/index: document action_template
0002-contrib.admin-allow-overriding-of-action-template-at.patch (3.8 KB) - added by Tay Ray Chuan 7 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 Tay Ray Chuan 6 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 7 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Changed 7 years ago by Tay Ray Chuan

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

comment:2 Changed 7 years ago by Tay Ray Chuan

Has patch: set
Owner: changed from nobody to Tay Ray Chuan
Status: newassigned

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 7 years ago by Tay Ray Chuan

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 7 years ago by Tay Ray Chuan

Summary: Admin templates rendered from templatetags cannot be overridden by applicationsadmin action templates cannot be overriden on a per-app basis

Changed 7 years ago by Tay Ray Chuan

admin/change_list.html: strip trailing whitespace

Changed 7 years ago by Tay Ray Chuan

ref/contrib/admin/index: document action_template

Changed 7 years ago by Tay Ray Chuan

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

comment:5 Changed 7 years ago by Tay Ray Chuan

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

comment:6 Changed 7 years ago by Tay Ray Chuan

Triage Stage: AcceptedReady for checkin

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

comment:7 Changed 7 years ago by Ramiro Morales

Needs tests: set
Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

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 6 years ago by Tay Ray Chuan

Needs tests: unset
Patch needs improvement: unset

comment:9 Changed 6 years ago by Tay Ray Chuan

Removed stray print.

comment:10 Changed 6 years ago by Matt McClanahan

Severity: Normal
Type: New feature

comment:11 Changed 6 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 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

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