Loading django/shortcuts.py +2 −21 Original line number Diff line number Diff line Loading @@ -3,9 +3,6 @@ This module collects helper functions and classes that "span" multiple levels of MVC. In other words, these functions/classes introduce controlled coupling for convenience's sake. """ import warnings from django.core import urlresolvers from django.db.models.base import ModelBase from django.db.models.manager import Manager Loading @@ -14,12 +11,10 @@ from django.http import ( Http404, HttpResponse, HttpResponsePermanentRedirect, HttpResponseRedirect, ) from django.template import RequestContext, loader from django.template.context import _current_app_undefined from django.template.engine import ( _context_instance_undefined, _dictionary_undefined, _dirs_undefined, ) from django.utils import six from django.utils.deprecation import RemovedInDjango110Warning from django.utils.encoding import force_text from django.utils.functional import Promise Loading Loading @@ -49,7 +44,7 @@ def render_to_response(template_name, context=None, def render(request, template_name, context=None, context_instance=_context_instance_undefined, content_type=None, status=None, current_app=_current_app_undefined, content_type=None, status=None, dirs=_dirs_undefined, dictionary=_dictionary_undefined, using=None): """ Loading @@ -58,32 +53,18 @@ def render(request, template_name, context=None, Uses a RequestContext by default. """ if (context_instance is _context_instance_undefined and current_app is _current_app_undefined and dirs is _dirs_undefined and dictionary is _dictionary_undefined): # No deprecated arguments were passed - use the new code path # In Django 1.10, request should become a positional argument. content = loader.render_to_string( template_name, context, request=request, using=using) else: # Some deprecated arguments were passed - use the legacy code path if context_instance is not _context_instance_undefined: if current_app is not _current_app_undefined: raise ValueError('If you provide a context_instance you must ' 'set its current_app before calling render()') pass else: context_instance = RequestContext(request) if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of render is deprecated. " "Set the current_app attribute of request instead.", RemovedInDjango110Warning, stacklevel=2) request.current_app = current_app # Directly set the private attribute to avoid triggering the # warning in RequestContext.__init__. context_instance._current_app = current_app content = loader.render_to_string( template_name, context, context_instance, dirs, dictionary, using=using) Loading django/template/context.py +2 −33 Original line number Diff line number Diff line import warnings from contextlib import contextmanager from copy import copy from django.utils.deprecation import RemovedInDjango110Warning # Hard-coded processor for easier use of CSRF protection. _builtin_context_processors = ('django.template.context_processors.csrf',) _current_app_undefined = object() class ContextPopException(Exception): "pop() has been called more times than push()" Loading Loading @@ -135,16 +130,8 @@ class BaseContext(object): class Context(BaseContext): "A stack container for variable context" def __init__(self, dict_=None, autoescape=True, current_app=_current_app_undefined, use_l10n=None, use_tz=None): if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of Context is deprecated. Use " "RequestContext and set the current_app attribute of its " "request instead.", RemovedInDjango110Warning, stacklevel=2) def __init__(self, dict_=None, autoescape=True, use_l10n=None, use_tz=None): self.autoescape = autoescape self._current_app = current_app self.use_l10n = use_l10n self.use_tz = use_tz self.template_name = "unknown" Loading @@ -154,14 +141,6 @@ class Context(BaseContext): self.template = None super(Context, self).__init__(dict_) @property def current_app(self): return None if self._current_app is _current_app_undefined else self._current_app @property def is_current_app_set(self): return self._current_app is not _current_app_undefined @contextmanager def bind_template(self, template): if self.template is not None: Loading Loading @@ -222,19 +201,9 @@ class RequestContext(Context): Additional processors can be specified as a list of callables using the "processors" keyword argument. """ def __init__(self, request, dict_=None, processors=None, current_app=_current_app_undefined, use_l10n=None, use_tz=None): # current_app isn't passed here to avoid triggering the deprecation # warning in Context.__init__. def __init__(self, request, dict_=None, processors=None, use_l10n=None, use_tz=None): super(RequestContext, self).__init__( dict_, use_l10n=use_l10n, use_tz=use_tz) if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of RequestContext is deprecated. " "Set the current_app attribute of its request instead.", RemovedInDjango110Warning, stacklevel=2) self._current_app = current_app self.request = request self._processors = () if processors is None else tuple(processors) self._processors_index = len(self.dicts) Loading django/template/defaulttags.py +2 −14 Original line number Diff line number Diff line Loading @@ -432,23 +432,11 @@ class URLNode(Node): smart_text(k, 'ascii'): v.resolve(context) for k, v in self.kwargs.items() } view_name = self.view_name.resolve(context) try: current_app = context.request.current_app except AttributeError: # Leave only the else block when the deprecation path for # Context.current_app completes in Django 1.10. # Can also remove the Context.is_current_app_set property. if context.is_current_app_set: current_app = context.current_app else: try: current_app = context.request.resolver_match.namespace except AttributeError: current_app = None # Try to look up the URL twice: once given the view name, and again # relative to what we guess is the "main" app. If they both fail, # re-raise the NoReverseMatch unless we're using the Loading django/template/response.py +3 −12 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from django.utils.deprecation import RemovedInDjango110Warning from .backends.django import Template as BackendTemplate from .base import Template from .context import Context, RequestContext, _current_app_undefined from .context import Context, RequestContext from .loader import get_template, select_template Loading Loading @@ -190,19 +190,10 @@ class SimpleTemplateResponse(HttpResponse): class TemplateResponse(SimpleTemplateResponse): rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request', '_current_app'] rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request'] def __init__(self, request, template, context=None, content_type=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: warnings.warn( "The current_app argument of TemplateResponse is deprecated. " "Set the current_app attribute of its request instead.", RemovedInDjango110Warning, stacklevel=2) request.current_app = current_app status=None, charset=None, using=None): super(TemplateResponse, self).__init__( template, context, content_type, status, charset, using) self._request = request docs/ref/template-response.txt +1 −11 Original line number Diff line number Diff line Loading @@ -189,7 +189,7 @@ TemplateResponse objects Methods ------- .. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, current_app=None, charset=None, using=None) .. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, charset=None, using=None) Instantiates a :class:`~django.template.response.TemplateResponse` object with the given request, template, context, content type, HTTP status, and Loading Loading @@ -224,16 +224,6 @@ Methods ``status`` The HTTP status code for the response. ``current_app`` A hint indicating which application contains the current view. See the :ref:`namespaced URL resolution strategy <topics-http-reversing-url-namespaces>` for more information. .. deprecated:: 1.8 The ``current_app`` argument is deprecated. Instead you should set ``request.current_app``. ``charset`` The charset in which the response will be encoded. If not given it will be extracted from ``content_type``, and if that is unsuccessful, the Loading Loading
django/shortcuts.py +2 −21 Original line number Diff line number Diff line Loading @@ -3,9 +3,6 @@ This module collects helper functions and classes that "span" multiple levels of MVC. In other words, these functions/classes introduce controlled coupling for convenience's sake. """ import warnings from django.core import urlresolvers from django.db.models.base import ModelBase from django.db.models.manager import Manager Loading @@ -14,12 +11,10 @@ from django.http import ( Http404, HttpResponse, HttpResponsePermanentRedirect, HttpResponseRedirect, ) from django.template import RequestContext, loader from django.template.context import _current_app_undefined from django.template.engine import ( _context_instance_undefined, _dictionary_undefined, _dirs_undefined, ) from django.utils import six from django.utils.deprecation import RemovedInDjango110Warning from django.utils.encoding import force_text from django.utils.functional import Promise Loading Loading @@ -49,7 +44,7 @@ def render_to_response(template_name, context=None, def render(request, template_name, context=None, context_instance=_context_instance_undefined, content_type=None, status=None, current_app=_current_app_undefined, content_type=None, status=None, dirs=_dirs_undefined, dictionary=_dictionary_undefined, using=None): """ Loading @@ -58,32 +53,18 @@ def render(request, template_name, context=None, Uses a RequestContext by default. """ if (context_instance is _context_instance_undefined and current_app is _current_app_undefined and dirs is _dirs_undefined and dictionary is _dictionary_undefined): # No deprecated arguments were passed - use the new code path # In Django 1.10, request should become a positional argument. content = loader.render_to_string( template_name, context, request=request, using=using) else: # Some deprecated arguments were passed - use the legacy code path if context_instance is not _context_instance_undefined: if current_app is not _current_app_undefined: raise ValueError('If you provide a context_instance you must ' 'set its current_app before calling render()') pass else: context_instance = RequestContext(request) if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of render is deprecated. " "Set the current_app attribute of request instead.", RemovedInDjango110Warning, stacklevel=2) request.current_app = current_app # Directly set the private attribute to avoid triggering the # warning in RequestContext.__init__. context_instance._current_app = current_app content = loader.render_to_string( template_name, context, context_instance, dirs, dictionary, using=using) Loading
django/template/context.py +2 −33 Original line number Diff line number Diff line import warnings from contextlib import contextmanager from copy import copy from django.utils.deprecation import RemovedInDjango110Warning # Hard-coded processor for easier use of CSRF protection. _builtin_context_processors = ('django.template.context_processors.csrf',) _current_app_undefined = object() class ContextPopException(Exception): "pop() has been called more times than push()" Loading Loading @@ -135,16 +130,8 @@ class BaseContext(object): class Context(BaseContext): "A stack container for variable context" def __init__(self, dict_=None, autoescape=True, current_app=_current_app_undefined, use_l10n=None, use_tz=None): if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of Context is deprecated. Use " "RequestContext and set the current_app attribute of its " "request instead.", RemovedInDjango110Warning, stacklevel=2) def __init__(self, dict_=None, autoescape=True, use_l10n=None, use_tz=None): self.autoescape = autoescape self._current_app = current_app self.use_l10n = use_l10n self.use_tz = use_tz self.template_name = "unknown" Loading @@ -154,14 +141,6 @@ class Context(BaseContext): self.template = None super(Context, self).__init__(dict_) @property def current_app(self): return None if self._current_app is _current_app_undefined else self._current_app @property def is_current_app_set(self): return self._current_app is not _current_app_undefined @contextmanager def bind_template(self, template): if self.template is not None: Loading Loading @@ -222,19 +201,9 @@ class RequestContext(Context): Additional processors can be specified as a list of callables using the "processors" keyword argument. """ def __init__(self, request, dict_=None, processors=None, current_app=_current_app_undefined, use_l10n=None, use_tz=None): # current_app isn't passed here to avoid triggering the deprecation # warning in Context.__init__. def __init__(self, request, dict_=None, processors=None, use_l10n=None, use_tz=None): super(RequestContext, self).__init__( dict_, use_l10n=use_l10n, use_tz=use_tz) if current_app is not _current_app_undefined: warnings.warn( "The current_app argument of RequestContext is deprecated. " "Set the current_app attribute of its request instead.", RemovedInDjango110Warning, stacklevel=2) self._current_app = current_app self.request = request self._processors = () if processors is None else tuple(processors) self._processors_index = len(self.dicts) Loading
django/template/defaulttags.py +2 −14 Original line number Diff line number Diff line Loading @@ -432,23 +432,11 @@ class URLNode(Node): smart_text(k, 'ascii'): v.resolve(context) for k, v in self.kwargs.items() } view_name = self.view_name.resolve(context) try: current_app = context.request.current_app except AttributeError: # Leave only the else block when the deprecation path for # Context.current_app completes in Django 1.10. # Can also remove the Context.is_current_app_set property. if context.is_current_app_set: current_app = context.current_app else: try: current_app = context.request.resolver_match.namespace except AttributeError: current_app = None # Try to look up the URL twice: once given the view name, and again # relative to what we guess is the "main" app. If they both fail, # re-raise the NoReverseMatch unless we're using the Loading
django/template/response.py +3 −12 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ from django.utils.deprecation import RemovedInDjango110Warning from .backends.django import Template as BackendTemplate from .base import Template from .context import Context, RequestContext, _current_app_undefined from .context import Context, RequestContext from .loader import get_template, select_template Loading Loading @@ -190,19 +190,10 @@ class SimpleTemplateResponse(HttpResponse): class TemplateResponse(SimpleTemplateResponse): rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request', '_current_app'] rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request'] def __init__(self, request, template, context=None, content_type=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: warnings.warn( "The current_app argument of TemplateResponse is deprecated. " "Set the current_app attribute of its request instead.", RemovedInDjango110Warning, stacklevel=2) request.current_app = current_app status=None, charset=None, using=None): super(TemplateResponse, self).__init__( template, context, content_type, status, charset, using) self._request = request
docs/ref/template-response.txt +1 −11 Original line number Diff line number Diff line Loading @@ -189,7 +189,7 @@ TemplateResponse objects Methods ------- .. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, current_app=None, charset=None, using=None) .. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, charset=None, using=None) Instantiates a :class:`~django.template.response.TemplateResponse` object with the given request, template, context, content type, HTTP status, and Loading Loading @@ -224,16 +224,6 @@ Methods ``status`` The HTTP status code for the response. ``current_app`` A hint indicating which application contains the current view. See the :ref:`namespaced URL resolution strategy <topics-http-reversing-url-namespaces>` for more information. .. deprecated:: 1.8 The ``current_app`` argument is deprecated. Instead you should set ``request.current_app``. ``charset`` The charset in which the response will be encoded. If not given it will be extracted from ``content_type``, and if that is unsuccessful, the Loading