Skip to content

Commit

Permalink
Fixed #15070 -- Also pass current_app and use_l10n in inclusion_tags.…
Browse files Browse the repository at this point in the history
… Thanks, raony, mk and goodtune.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16117 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Apr 28, 2011
1 parent 07854d1 commit 2ac4f17
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion django/template/base.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -930,7 +930,11 @@ def render(self, context):
else: else:
t = get_template(file_name) t = get_template(file_name)
self.nodelist = t.nodelist self.nodelist = t.nodelist
new_context = context_class(dict, autoescape=context.autoescape) new_context = context_class(dict, **{
'autoescape': context.autoescape,
'current_app': context.current_app,
'use_l10n': context.use_l10n,
})
# Copy across the CSRF token, if present, because inclusion # Copy across the CSRF token, if present, because inclusion
# tags are often used for forms, and we need instructions # tags are often used for forms, and we need instructions
# for using CSRF protection to be as simple as possible. # for using CSRF protection to be as simple as possible.
Expand Down
24 changes: 24 additions & 0 deletions tests/regressiontests/templates/custom.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,3 +78,27 @@ def test_inclusion_tag_registration(self):
self.verify_tag(custom.inclusion_explicit_no_context, 'inclusion_explicit_no_context') self.verify_tag(custom.inclusion_explicit_no_context, 'inclusion_explicit_no_context')
self.verify_tag(custom.inclusion_no_params_with_context, 'inclusion_no_params_with_context') self.verify_tag(custom.inclusion_no_params_with_context, 'inclusion_no_params_with_context')
self.verify_tag(custom.inclusion_params_and_context, 'inclusion_params_and_context') self.verify_tag(custom.inclusion_params_and_context, 'inclusion_params_and_context')

def test_15070_current_app(self):
"""
Test that inclusion tag passes down `current_app` of context to the
Context of the included/rendered template as well.
"""
c = template.Context({})
t = template.Template('{% load custom %}{% inclusion_tag_current_app %}')
self.assertEquals(t.render(c).strip(), u'None')

c.current_app = 'advanced'
self.assertEquals(t.render(c).strip(), u'advanced')

def test_15070_use_l10n(self):
"""
Test that inclusion tag passes down `use_l10n` of context to the
Context of the included/rendered template as well.
"""
c = template.Context({})
t = template.Template('{% load custom %}{% inclusion_tag_use_l10n %}')
self.assertEquals(t.render(c).strip(), u'None')

c.use_l10n = True
self.assertEquals(t.render(c).strip(), u'True')
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
{% load custom %}{% current_app %}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
{% load custom %}{% use_l10n %}
15 changes: 15 additions & 0 deletions tests/regressiontests/templates/templatetags/custom.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ def inclusion_params_and_context(context, arg):
return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)} return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__" inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"


@register.simple_tag(takes_context=True)
def current_app(context):
return "%s" % context.current_app

@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
def inclusion_tag_current_app(context):
return {}

@register.simple_tag(takes_context=True)
def use_l10n(context):
return "%s" % context.use_l10n

@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
def inclusion_tag_use_l10n(context):
return {}

0 comments on commit 2ac4f17

Please sign in to comment.