Ticket #24538: 0001-Made-sure-self-can-t-be-overriden-in-Jinja.patch

File 0001-Made-sure-self-can-t-be-overriden-in-Jinja.patch, 2.4 KB (added by Simon Charette, 10 years ago)
  • django/template/backends/jinja2.py

    From 98d45228a76618fd0e4137742864fd03ddc1b402 Mon Sep 17 00:00:00 2001
    From: Simon Charette <charette.s@gmail.com>
    Date: Thu, 26 Mar 2015 03:19:24 -0400
    Subject: [PATCH] Made sure self can't be overriden in Jinja.
    
    ---
     django/template/backends/jinja2.py                            | 2 +-
     tests/template_backends/jinja2/template_backends/self.html    | 1 +
     tests/template_backends/templates/template_backends/self.html | 1 +
     tests/template_backends/test_dummy.py                         | 5 +++++
     4 files changed, 8 insertions(+), 1 deletion(-)
     create mode 100644 tests/template_backends/jinja2/template_backends/self.html
     create mode 100644 tests/template_backends/templates/template_backends/self.html
    
    diff --git a/django/template/backends/jinja2.py b/django/template/backends/jinja2.py
    index b26cb39..0863773 100644
    a b class Template(object):  
    6060            context['request'] = request
    6161            context['csrf_input'] = csrf_input_lazy(request)
    6262            context['csrf_token'] = csrf_token_lazy(request)
    63         return self.template.render(**context)
     63        return self.template.render(context)
  • new file tests/template_backends/jinja2/template_backends/self.html

    diff --git a/tests/template_backends/jinja2/template_backends/self.html b/tests/template_backends/jinja2/template_backends/self.html
    new file mode 100644
    index 0000000..e3125de
    - +  
     1{{ self }}
  • new file tests/template_backends/templates/template_backends/self.html

    diff --git a/tests/template_backends/templates/template_backends/self.html b/tests/template_backends/templates/template_backends/self.html
    new file mode 100644
    index 0000000..e3125de
    - +  
     1{{ self }}
  • tests/template_backends/test_dummy.py

    diff --git a/tests/template_backends/test_dummy.py b/tests/template_backends/test_dummy.py
    index b529b70..943c76c 100644
    a b class TemplateStringsTests(SimpleTestCase):  
    9393        template = self.engine.get_template('template_backends/hello.html')
    9494        content = template.render({'name': 'Jérôme'})
    9595        self.assertEqual(content, "Hello Jérôme!\n")
     96
     97    def test_context_self(self):
     98        template = self.engine.get_template('template_backends/self.html')
     99        content = template.render({'self': 'Self'})
     100        self.assertEqual(content, "Self\n")
Back to Top