summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-04-28 13:41:28 +0000
committerJannis Leidel <jannis@leidel.info>2011-04-28 13:41:28 +0000
commit2ac4f175ec7ec5f6122d079e7f1dbac4800e7657 (patch)
tree9e9f47ccbf61dccdd9adaa38827fd0f4aedccf03
parent07854d1c44fcf1243afeec087f31651fd5c2264b (diff)
Fixed #15070 -- Also pass current_app and use_l10n in inclusion_tags. Thanks, raony, mk and goodtune.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16117 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/base.py6
-rw-r--r--tests/regressiontests/templates/custom.py24
-rw-r--r--tests/regressiontests/templates/templates/test_incl_tag_current_app.html1
-rw-r--r--tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html1
-rw-r--r--tests/regressiontests/templates/templatetags/custom.py15
5 files changed, 46 insertions, 1 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 08ff5c6d52..b6470f3e91 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -930,7 +930,11 @@ class Library(object):
else:
t = get_template(file_name)
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
# tags are often used for forms, and we need instructions
# for using CSRF protection to be as simple as possible.
diff --git a/tests/regressiontests/templates/custom.py b/tests/regressiontests/templates/custom.py
index fe5b095207..7ca359d976 100644
--- a/tests/regressiontests/templates/custom.py
+++ b/tests/regressiontests/templates/custom.py
@@ -78,3 +78,27 @@ class CustomTagTests(TestCase):
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_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')
diff --git a/tests/regressiontests/templates/templates/test_incl_tag_current_app.html b/tests/regressiontests/templates/templates/test_incl_tag_current_app.html
new file mode 100644
index 0000000000..ab2fe63b6f
--- /dev/null
+++ b/tests/regressiontests/templates/templates/test_incl_tag_current_app.html
@@ -0,0 +1 @@
+{% load custom %}{% current_app %}
diff --git a/tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html b/tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html
new file mode 100644
index 0000000000..3054960d16
--- /dev/null
+++ b/tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html
@@ -0,0 +1 @@
+{% load custom %}{% use_l10n %}
diff --git a/tests/regressiontests/templates/templatetags/custom.py b/tests/regressiontests/templates/templatetags/custom.py
index b2e8a1681c..8db113a6f1 100644
--- a/tests/regressiontests/templates/templatetags/custom.py
+++ b/tests/regressiontests/templates/templatetags/custom.py
@@ -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)}
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 {}