Ticket #15070: 15070_goodtune.diff

File 15070_goodtune.diff, 3.9 KB (added by Gary Reynolds, 14 years ago)
  • django/template/base.py

     
    930930                        else:
    931931                            t = get_template(file_name)
    932932                        self.nodelist = t.nodelist
    933                     new_context = context_class(dict, autoescape=context.autoescape)
     933                    new_context = context_class(dict, autoescape=context.autoescape, current_app=context.current_app, use_l10n=context.use_l10n)
    934934                    # Copy across the CSRF token, if present, because inclusion
    935935                    # tags are often used for forms, and we need instructions
    936936                    # for using CSRF protection to be as simple as possible.
  • tests/regressiontests/templates/templatetags/custom.py

     
    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_current_app.html', takes_context=True)
     77def inclusion_tag_current_app(context):
     78    return {}
     79
     80@register.simple_tag(takes_context=True)
     81def use_l10n(context):
     82    return "%s" % context.use_l10n
     83
     84@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
     85def inclusion_tag_use_l10n(context):
     86    return {}
  • tests/regressiontests/templates/templates/test_incl_tag_current_app.html

     
     1{% load custom %}{% current_app %}
  • tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html

     
     1{% load custom %}{% use_l10n %}
  • tests/regressiontests/templates/custom.py

     
    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_current_app(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_current_app %}')
     89        self.assertEquals(t.render(c).strip(), u'None')
     90
     91        c.current_app = 'advanced'
     92        self.assertEquals(t.render(c).strip(), u'advanced')
     93
     94    def test_15070_use_l10n(self):
     95        '''
     96        Test that inclusion tag passes down `use_l10n` of context to the
     97        Context of the included/rendered template as well.
     98        '''
     99        c = template.Context({})
     100        t = template.Template('{% load custom %}{% inclusion_tag_use_l10n %}')
     101        self.assertEquals(t.render(c).strip(), u'None')
     102
     103        c.use_l10n = True
     104        self.assertEquals(t.render(c).strip(), u'True')
Back to Top