|
@@ -1,12 +1,6 @@
|
|
|
-import warnings
|
|
|
-
|
|
|
from django.http import HttpResponse
|
|
|
from django.utils import six
|
|
|
-from django.utils.deprecation import RemovedInDjango110Warning
|
|
|
|
|
|
-from .backends.django import Template as BackendTemplate
|
|
|
-from .base import Template
|
|
|
-from .context import Context, RequestContext
|
|
|
from .loader import get_template, select_template
|
|
|
|
|
|
|
|
@@ -19,14 +13,6 @@ class SimpleTemplateResponse(HttpResponse):
|
|
|
|
|
|
def __init__(self, template, context=None, content_type=None, status=None,
|
|
|
charset=None, using=None):
|
|
|
- if isinstance(template, Template):
|
|
|
- warnings.warn(
|
|
|
- "{}'s template argument cannot be a django.template.Template "
|
|
|
- "anymore. It may be a backend-specific template like those "
|
|
|
- "created by get_template().".format(self.__class__.__name__),
|
|
|
- RemovedInDjango110Warning, stacklevel=2)
|
|
|
- template = BackendTemplate(template)
|
|
|
-
|
|
|
# It would seem obvious to call these next two members 'template' and
|
|
|
# 'context', but those names are reserved as part of the test Client
|
|
|
# API. To avoid the name collision, we use different names.
|
|
@@ -83,46 +69,9 @@ class SimpleTemplateResponse(HttpResponse):
|
|
|
else:
|
|
|
return template
|
|
|
|
|
|
- def _resolve_template(self, template):
|
|
|
- # This wrapper deprecates returning a django.template.Template in
|
|
|
- # subclasses that override resolve_template. It can be removed in
|
|
|
- # Django 1.10.
|
|
|
- new_template = self.resolve_template(template)
|
|
|
- if isinstance(new_template, Template):
|
|
|
- warnings.warn(
|
|
|
- "{}.resolve_template() must return a backend-specific "
|
|
|
- "template like those created by get_template(), not a "
|
|
|
- "{}.".format(
|
|
|
- self.__class__.__name__, new_template.__class__.__name__),
|
|
|
- RemovedInDjango110Warning, stacklevel=2)
|
|
|
- new_template = BackendTemplate(new_template)
|
|
|
- return new_template
|
|
|
-
|
|
|
def resolve_context(self, context):
|
|
|
return context
|
|
|
|
|
|
- def _resolve_context(self, context):
|
|
|
- # This wrapper deprecates returning a Context or a RequestContext in
|
|
|
- # subclasses that override resolve_context. It can be removed in
|
|
|
- # Django 1.10. If returning a Context or a RequestContext works by
|
|
|
- # accident, it won't be an issue per se, but it won't be officially
|
|
|
- # supported either.
|
|
|
- new_context = self.resolve_context(context)
|
|
|
- if isinstance(new_context, RequestContext) and self._request is None:
|
|
|
- self._request = new_context.request
|
|
|
- if isinstance(new_context, Context):
|
|
|
- warnings.warn(
|
|
|
- "{}.resolve_context() must return a dict, not a {}.".format(
|
|
|
- self.__class__.__name__, new_context.__class__.__name__),
|
|
|
- RemovedInDjango110Warning, stacklevel=2)
|
|
|
- # It would be tempting to do new_context = new_context.flatten()
|
|
|
- # here but that would cause template context processors to run for
|
|
|
- # TemplateResponse(request, template, Context({})), which would be
|
|
|
- # backwards-incompatible. As a consequence another deprecation
|
|
|
- # warning will be raised when rendering the template. There isn't
|
|
|
- # much we can do about that.
|
|
|
- return new_context
|
|
|
-
|
|
|
@property
|
|
|
def rendered_content(self):
|
|
|
"""Returns the freshly rendered content for the template and context
|
|
@@ -132,8 +81,8 @@ class SimpleTemplateResponse(HttpResponse):
|
|
|
response content, you must either call render(), or set the
|
|
|
content explicitly using the value of this property.
|
|
|
"""
|
|
|
- template = self._resolve_template(self.template_name)
|
|
|
- context = self._resolve_context(self.context_data)
|
|
|
+ template = self.resolve_template(self.template_name)
|
|
|
+ context = self.resolve_context(self.context_data)
|
|
|
content = template.render(context, self._request)
|
|
|
return content
|
|
|
|