Ticket #15070: 15070.2.diff

File 15070.2.diff, 2.8 KB (added by Matthias Kestenholz, 14 years ago)
  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index b8d6c13..1babda9 100644
    a b class Library(object):  
    928928                        else:
    929929                            t = get_template(file_name)
    930930                        self.nodelist = t.nodelist
    931                     new_context = context_class(dict, autoescape=context.autoescape)
     931                    new_context = context_class(dict, autoescape=context.autoescape, current_app=context.current_app)
    932932                    # Copy across the CSRF token, if present, because inclusion
    933933                    # tags are often used for forms, and we need instructions
    934934                    # 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 fe5b095..36ca712 100644
    a b class CustomTagTests(TestCase):  
    7878        self.verify_tag(custom.inclusion_explicit_no_context, 'inclusion_explicit_no_context')
    7979        self.verify_tag(custom.inclusion_no_params_with_context, 'inclusion_no_params_with_context')
    8080        self.verify_tag(custom.inclusion_params_and_context, 'inclusion_params_and_context')
     81
     82    def test_15070(self):
     83        '''
     84        Test that inclusion tag passes down `current_app` of context to the
     85        Context of the included/rendered template as well.
     86        '''
     87        c = template.Context({})
     88        t = template.Template('{% load custom %}{% inclusion_tag_no_params %}')
     89        self.assertEquals(t.render(c).strip(), u'None')
     90
     91        c.current_app = 'advanced'
     92        self.assertEquals(t.render(c).strip(), 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 b2e8a16..bbdbbcf 100644
    a b def inclusion_params_and_context(context, arg):  
    6969    return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
    7070inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
    7171
     72@register.simple_tag(takes_context=True)
     73def current_app(context):
     74    return "%s" % context.current_app
     75
     76@register.inclusion_tag('test_incl_tag.html', takes_context=True)
     77def inclusion_tag_no_params(context):
     78    return {}
Back to Top