mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.8.x] Fixed #24168 -- Allowed selecting a template engine in a few APIs.
Specifically in rendering shortcuts, template responses, and class-based views that return template responses. Also added a test for render_to_response(status=...) which was missing fromfdbfc980. Thanks Tim and Carl for the review. Backport of2133f31from master. Conflicts: docs/topics/http/shortcuts.txt tests/generic_views/test_base.py
This commit is contained in:
		| @@ -16,7 +16,7 @@ class SimpleTemplateResponse(HttpResponse): | ||||
|     rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks'] | ||||
|  | ||||
|     def __init__(self, template, context=None, content_type=None, status=None, | ||||
|                  charset=None): | ||||
|                  charset=None, using=None): | ||||
|         if isinstance(template, Template): | ||||
|             warnings.warn( | ||||
|                 "{}'s template argument cannot be a django.template.Template " | ||||
| @@ -31,6 +31,8 @@ class SimpleTemplateResponse(HttpResponse): | ||||
|         self.template_name = template | ||||
|         self.context_data = context | ||||
|  | ||||
|         self.using = using | ||||
|  | ||||
|         self._post_render_callbacks = [] | ||||
|  | ||||
|         # _request stores the current request object in subclasses that know | ||||
| @@ -73,9 +75,9 @@ class SimpleTemplateResponse(HttpResponse): | ||||
|     def resolve_template(self, template): | ||||
|         "Accepts a template object, path-to-template or list of paths" | ||||
|         if isinstance(template, (list, tuple)): | ||||
|             return loader.select_template(template) | ||||
|             return loader.select_template(template, using=self.using) | ||||
|         elif isinstance(template, six.string_types): | ||||
|             return loader.get_template(template) | ||||
|             return loader.get_template(template, using=self.using) | ||||
|         else: | ||||
|             return template | ||||
|  | ||||
| @@ -189,7 +191,8 @@ class TemplateResponse(SimpleTemplateResponse): | ||||
|     rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request', '_current_app'] | ||||
|  | ||||
|     def __init__(self, request, template, context=None, content_type=None, | ||||
|             status=None, current_app=_current_app_undefined, charset=None): | ||||
|             status=None, current_app=_current_app_undefined, charset=None, | ||||
|             using=None): | ||||
|         # As a convenience we'll allow callers to provide current_app without | ||||
|         # having to avoid needing to create the RequestContext directly | ||||
|         if current_app is not _current_app_undefined: | ||||
| @@ -199,5 +202,5 @@ class TemplateResponse(SimpleTemplateResponse): | ||||
|                 RemovedInDjango20Warning, stacklevel=2) | ||||
|             request.current_app = current_app | ||||
|         super(TemplateResponse, self).__init__( | ||||
|             template, context, content_type, status, charset) | ||||
|             template, context, content_type, status, charset, using) | ||||
|         self._request = request | ||||
|   | ||||
		Reference in New Issue
	
	Block a user