Opened 7 years ago

Last modified 2 years ago

#8158 new New feature

Make possible to extend some of admin's templates

Reported by: marinho Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: semente@…, andybak, mofle Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The current admin/index.html template should be renamed to admin/base_index.html and a new admin/index.html created with only a {% extends "admin/base_index.html" %}, to make possible extends the Admin index page with no needs to generate a new and non-dynamic file using manage.py admin_index command.

This is a little change that can helps developers to avoid rewrite a customized AdminSite.index method or generate a static template.

Attachments (2)

8158.diff (5.7 KB) - added by marinho 7 years ago.
testproject.tar.gz (10.7 KB) - added by pmartin 4 years ago.

Download all attachments as: .zip

Change History (24)

Changed 7 years ago by marinho

comment:1 Changed 7 years ago by marinho

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by julien

  • Triage Stage changed from Unreviewed to Accepted

+1 for this. The index.html template is currently not extensible (provokes recursive importing). Moving all the code to an extra file base_index.html seems like a good approach to me.

comment:3 Changed 7 years ago by julianb

  • milestone set to 1.0 maybe

comment:4 Changed 7 years ago by Guilherme M. Gondim <semente@…>

  • Cc semente@… added

comment:5 Changed 7 years ago by jacob

  • milestone changed from 1.0 maybe to 1.0

comment:6 Changed 7 years ago by jacob

  • milestone changed from 1.0 to post-1.0

This really just papers over a bigger problem, that of letting a template extend its parent (like Jinja `{% extends "!parent.html" %}). I'm going to call this a "feature" and push it post-1.0; for now folks can just copy/paste.

comment:7 Changed 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:8 Changed 6 years ago by lpetrov

any updates?

comment:9 Changed 5 years ago by rctay

  • Resolution set to worksforme
  • Status changed from new to closed

While we await the {% extends "!parent.html" %} feature (I don't know if this planned or not), one could do this in the meantime:

{% extends '/path/to/default/admin/templates/admin/base.html' %}

comment:10 Changed 5 years ago by lukeplant

Another way to do the above is to have a template directory which contains the other template directories (possibly via symlinks). This is added to the end of your TEMPLATE_DIRS. Then, the tag looks like:

{% extends 'alltemplate/admin/base.html' %}

See ExtendingTemplates

comment:11 Changed 5 years ago by julien

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I don't think this ticket should have been closed. No decision has been taken yet about whether or not the template extension system will be improved to cover this issue.

comment:12 Changed 5 years ago by vinyll

making a symlink and extending it does the trick.
However, +1 for making it extendable.

comment:13 Changed 4 years ago by mk

Related tickets:
#2414 coredump of python by a template extending itself
#14140 There is no way to override admin templates to the project level

comment:14 Changed 4 years ago by marinho

  • Summary changed from Make possible to extend admin/index.html to Make possible to extend some of admin's templates

This change should be done for many of admin templates, like:

  • app_index.html
  • change_form.html
  • change_list.html
  • delete_confirmation.html
  • index.html
  • login.html
  • object_history.html

All of those above could be renamed as "base_*" and a new one with original name would just "{% extends "base_..." %}" .

The worst part on customizing Admin is to make a symlink of admin's templates directory with a fake name to can extend them to avoid a bad copy/paste of all a directory. It works, but it's a quick fix.

I think: what's the problem with this idea, if many other things in Django does the same? (i.e.: every class and templates starting with "base... ")

comment:15 Changed 4 years ago by marinho

BTW, Jacob, I guess that allow extending from another template with the same name, like a parent as Jinja does is incompatible with Django's model for templates.

Because Django just finds a template by name in the sequence of template loaders and their internal sequences (usually TEMPLATE_DIRS and INSTALLED_APPS).

There's no "parent", really. What's there is just a template that is found before another with the same name, so, how could we say to a template to extend its parent? Skipping its own to find the next in the sequency of paths?

So, I guess this would be a worse trick than just rename those templates as base_* and extend them to the right name.

comment:16 Changed 4 years ago by jacmkno

Another ticket about this issue: http://code.djangoproject.com/ticket/14140. I think a good solution would be to change the template look up process to prevent cycles, initially by ignoring a template path which is the same as the template that triggered the lookup, and beyond, by changing the lookup algorithm to flag "search nodes" in order to prevent multi-node cycles.

comment:17 Changed 4 years ago by jacmkno

  • Has patch unset

Another ticket about this issue: #14140. I think a good solution would be to change the template look up process to prevent cycles, initially by ignoring a template path which is the same as the template that triggered the lookup, and beyond, by changing the lookup algorithm to flag "search nodes" in order to prevent multi-node cycles.

Changed 4 years ago by pmartin

comment:18 Changed 4 years ago by pmartin

We have implemented a generic solution for a template so that a template loader can extend another template from another template loader. Both templates have the same name.It is described in ticket #15053.

I am going to upload a sample project. You can see the example visiting the admin site index or a change list. This project work with trunk.

I think the principal is the idea:

  • It makes sense that a template of a project extends a template for an application, both templates have the same name.
  • It makes sense that a template of a project extends a template of an egg, both templates have the same name.
  • It makes sense that a template for an application extends a template of an egg, both templates have the same name.

A template can extend always of another template of another template loader if the order of the template loaders are the correct.

It's posible that exists a case where a template of an application extends another template of another application, with the same name, but it's a strange case, this case will be hard to debug, and this should be delegated to the template loader "app_directories".

comment:19 Changed 4 years ago by andybak

  • Cc andybak added

comment:20 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:21 Changed 4 years ago by mofle

  • Cc mofle added
  • Easy pickings unset
  • UI/UX unset

comment:22 Changed 2 years ago by aaugustin

  • Status changed from reopened to new
Note: See TracTickets for help on using tickets.
Back to Top