Ticket #15070: 15070_with_tests.patch

File 15070_with_tests.patch, 2.7 KB (added by Béres Botond, 13 years ago)
  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index 49ef0b8..02f947a 100644
    a b class Library(object):  
    927927                        else:
    928928                            t = get_template(file_name)
    929929                        self.nodelist = t.nodelist
    930                     new_context = context_class(dict, autoescape=context.autoescape)
     930                    new_context = context_class(dict, autoescape=context.autoescape, current_app=context.current_app)
    931931                    # Copy across the CSRF token, if present, because inclusion
    932932                    # tags are often used for forms, and we need instructions
    933933                    # for using CSRF protection to be as simple as possible.
  • tests/regressiontests/templates/custom.py

    diff --git a/tests/regressiontests/templates/custom.py b/tests/regressiontests/templates/custom.py
    index a517bd1..289238c 100644
    a b class CustomTagTests(TestCase):  
    5252        register = template.Library()
    5353        decorator = register.simple_tag(takes_context=True)
    5454        self.assertRaises(template.TemplateSyntaxError, decorator, a_simple_tag_without_parameters)
     55
     56    def test_15070(self):
     57        '''
     58        Test that inclusion tag passes down `current_app` of context to the
     59        Context of the included/rendered template as well.
     60        '''
     61        c = template.Context({})
     62        t = template.Template('{% load custom %}{% inclusion_tag_no_params %}')
     63        self.assertEquals(t.render(c), u'None')
     64       
     65        c.current_app = 'advanced'
     66        self.assertEquals(t.render(c), u'advanced')
  • new file tests/regressiontests/templates/templates/test_incl_tag.html

    diff --git a/tests/regressiontests/templates/templates/test_incl_tag.html b/tests/regressiontests/templates/templates/test_incl_tag.html
    new file mode 100644
    index 0000000..ab2fe63
    - +  
     1{% load custom %}{% current_app %}
  • tests/regressiontests/templates/templatetags/custom.py

    diff --git a/tests/regressiontests/templates/templatetags/custom.py b/tests/regressiontests/templates/templatetags/custom.py
    index 7011316..588ad69 100644
    a b def params_and_context(context, arg):  
    3939    return "params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)
    4040params_and_context.anything = "Expected params_and_context __dict__"
    4141
     42@register.simple_tag(takes_context=True)
     43def current_app(context):
     44    return "%s" % context.current_app
     45
     46@register.inclusion_tag('test_incl_tag.html', takes_context=True)
     47def inclusion_tag_no_params(context):
     48    return {}
Back to Top