Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#12292 closed (wontfix)

render_to_response method on AdminSite and ModelAdmin

Reported by: LeafStorm Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have written a patch against trunk to add a render_to_response method to AdminSite and ModelAdmin. The method replaces the

context_instance = template.RequestContext(request, current_app=self.name)
return render_to_response(templates, context, context_instance=context_instance)

idiom at the end of admin views with:

return self.render_to_response(request, templates, context)

This may seem like a small change, but it allows the method in which admin templates are rendered to be overridden. This can be used to inject extra values into the context for customized templates, or to possibly replace the Django template language with an external template language like Jinja2 or Mako in the admin ("loose coupling"). It also reduces the boilerplate in the admin and makes it easier to upgrade in the event that the template API changes ("don't repeat yourself").

The included patch includes documentation updates, but no code outside the admin has been changed (so the rest of the trunk may need updating to use the new method). All admin-related tests have been run on the patch, and it is very unlikely to break backwards compatibility, due to the fact that it merely places the code that was used before in another place.

Attachments (1)

admin-render-to-response.diff (9.5 KB ) - added by LeafStorm 14 years ago.

Download all attachments as: .zip

Change History (3)

by LeafStorm, 14 years ago

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: newclosed

I'm marking this wontfix. I'm not rejecting the idea of using non-Django template languages - just suggesting that there is a better way. Specifically, #6262/r11862 should make it possible to write a Jinja/Mako template loader without needing any changes to Django core. The process for using non-Django template languages is documented in abstract terms, but the abstract example should map fairly closely to the Jinja experience:

http://docs.djangoproject.com/en/dev/ref/templates/api/#using-an-alternative-template-language

comment:2 by Nick Sandford, 14 years ago

I kind of saw it as a neat way to add some extra context to a ModelAdmin..

you could do:

class FooAdmin(admin.ModelAdmin):
    def render_to_response(request, template, context):
        context.update({'foo': 'bar'})
        return super(FooAdmin, self).render_to_response(request, template, context)
Note: See TracTickets for help on using tickets.
Back to Top