Ticket #25469: autoescape-setting.patch

File autoescape-setting.patch, 5.2 KB (added by Aymeric Augustin, 9 years ago)
  • django/template/backends/django.py

    diff --git a/django/template/backends/django.py b/django/template/backends/django.py
    index af58f60..897b766 100644
    a b class DjangoTemplates(BaseEngine):  
    2323    def __init__(self, params):
    2424        params = params.copy()
    2525        options = params.pop('OPTIONS').copy()
     26        options.setdefault('autoescape', True)
    2627        options.setdefault('debug', settings.DEBUG)
    2728        options.setdefault('file_charset', settings.FILE_CHARSET)
    2829        libraries = options.get('libraries', {})
    class Template(object):  
    6061        return self.template.origin
    6162
    6263    def render(self, context=None, request=None):
    63         context = make_context(context, request)
     64        context = make_context(context, request,
     65                               autoescape=self.backend.engine.autoescape)
    6466        try:
    6567            return self.template.render(context)
    6668        except TemplateDoesNotExist as exc:
  • django/template/context.py

    diff --git a/django/template/context.py b/django/template/context.py
    index 2643e92..1d70f45 100644
    a b class RequestContext(Context):  
    245245        return new_context
    246246
    247247
    248 def make_context(context, request=None):
     248def make_context(context, request=None, **kwargs):
    249249    """
    250250    Create a suitable Context from a plain dict and optionally an HttpRequest.
    251251    """
    252252    if request is None:
    253         context = Context(context)
     253        context = Context(context, **kwargs)
    254254    else:
    255255        # The following pattern is required to ensure values from
    256256        # context override those from template context processors.
    257257        original_context = context
    258         context = RequestContext(request)
     258        context = RequestContext(request, **kwargs)
    259259        if original_context:
    260260            context.push(original_context)
    261261    return context
  • django/template/engine.py

    diff --git a/django/template/engine.py b/django/template/engine.py
    index d439f49..2305b6b 100644
    a b class Engine(object):  
    1616        'django.template.loader_tags',
    1717    ]
    1818
    19     def __init__(self, dirs=None, app_dirs=False, context_processors=None,
    20                  debug=False, loaders=None, string_if_invalid='',
    21                  file_charset='utf-8', libraries=None, builtins=None):
     19    def __init__(self, dirs=None, app_dirs=False, autoescape=True,
     20                 context_processors=None, debug=False, loaders=None,
     21                 string_if_invalid='', file_charset='utf-8',
     22                 libraries=None, builtins=None):
    2223        if dirs is None:
    2324            dirs = []
    2425        if context_processors is None:
    class Engine(object):  
    3839
    3940        self.dirs = dirs
    4041        self.app_dirs = app_dirs
     42        self.autoescape = autoescape
    4143        self.context_processors = context_processors
    4244        self.debug = debug
    4345        self.loaders = loaders
  • docs/ref/templates/api.txt

    diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
    index 570ffbc..796d945 100644
    a b probably isn't the documentation you're looking for. An instance of the  
    4848of that backend and any attribute defaults mentioned below are overridden by
    4949what's passed by :class:`~django.template.backends.django.DjangoTemplates`.
    5050
    51 .. class:: Engine(dirs=None, app_dirs=False, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8', libraries=None, builtins=None)
     51.. class:: Engine(dirs=None, app_dirs=False, autocomplete=True, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8', libraries=None, builtins=None)
    5252
    5353    When instantiating an ``Engine`` all arguments must be passed as keyword
    5454    arguments:
    what's passed by :class:`~django.template.backends.django.DjangoTemplates`.  
    6363
    6464      It defaults to ``False``.
    6565
     66    * ``autocomplete`` controls whether HTML autoescaping is enabled.
     67
     68      It default to ``True``.
     69
     70      .. warning::
     71
     72          Only set it to ``False`` if you're rendering non-HTML templates!
     73
     74      .. versionadded:: 1.10
     75
     76          The ``autocomplete`` option was added.
     77
    6678    * ``context_processors`` is a list of dotted Python paths to callables
    6779      that are used to populate the context when a template is rendered with a
    6880      request. These callables take a request object as their argument and
  • docs/topics/templates.txt

    diff --git a/docs/topics/templates.txt b/docs/topics/templates.txt
    index f0abccc..5da754e 100644
    a b applications. This generic name was kept for backwards-compatibility.  
    295295``DjangoTemplates`` engines accept the following :setting:`OPTIONS
    296296<TEMPLATES-OPTIONS>`:
    297297
     298* ``'autocomplete'``: a boolean that controls whether HTML autoescaping is
     299  enabled.
     300
     301  It default to ``True``.
     302
     303  .. warning::
     304
     305      Only set it to ``False`` if you're rendering non-HTML templates!
     306
     307  .. versionadded:: 1.10
     308
     309      The ``autocomplete`` option was added.
     310
    298311* ``'context_processors'``: a list of dotted Python paths to callables that
    299312  are used to populate the context when a template is rendered with a request.
    300313  These callables take a request object as their argument and return a
Back to Top