render_to_response method on AdminSite and ModelAdmin
|Reported by:||LeafStorm||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have written a patch against trunk to add a
render_to_response method to
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.