Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 2ac4f175ec7ec5f6122d079e7f1dbac4800e7657 1 parent 07854d1
Jannis Leidel authored April 28, 2011
6  django/template/base.py
@@ -930,7 +930,11 @@ def render(self, context):
930 930
                         else:
931 931
                             t = get_template(file_name)
932 932
                         self.nodelist = t.nodelist
933  
-                    new_context = context_class(dict, autoescape=context.autoescape)
  933
+                    new_context = context_class(dict, **{
  934
+                        'autoescape': context.autoescape,
  935
+                        'current_app': context.current_app,
  936
+                        'use_l10n': context.use_l10n,
  937
+                    })
934 938
                     # Copy across the CSRF token, if present, because inclusion
935 939
                     # tags are often used for forms, and we need instructions
936 940
                     # for using CSRF protection to be as simple as possible.
24  tests/regressiontests/templates/custom.py
@@ -78,3 +78,27 @@ def test_inclusion_tag_registration(self):
78 78
         self.verify_tag(custom.inclusion_explicit_no_context, 'inclusion_explicit_no_context')
79 79
         self.verify_tag(custom.inclusion_no_params_with_context, 'inclusion_no_params_with_context')
80 80
         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')
1  tests/regressiontests/templates/templates/test_incl_tag_current_app.html
... ...
@@ -0,0 +1 @@
  1
+{% load custom %}{% current_app %}
1  tests/regressiontests/templates/templates/test_incl_tag_use_l10n.html
... ...
@@ -0,0 +1 @@
  1
+{% load custom %}{% use_l10n %}
15  tests/regressiontests/templates/templatetags/custom.py
@@ -69,3 +69,18 @@ def inclusion_params_and_context(context, arg):
69 69
     return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
70 70
 inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
71 71
 
  72
+@register.simple_tag(takes_context=True)
  73
+def current_app(context):
  74
+    return "%s" % context.current_app
  75
+
  76
+@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
  77
+def inclusion_tag_current_app(context):
  78
+    return {}
  79
+
  80
+@register.simple_tag(takes_context=True)
  81
+def use_l10n(context):
  82
+    return "%s" % context.use_l10n
  83
+
  84
+@register.inclusion_tag('test_incl_tag_use_l10n.html', takes_context=True)
  85
+def inclusion_tag_use_l10n(context):
  86
+    return {}

0 notes on commit 2ac4f17

Please sign in to comment.
Something went wrong with that request. Please try again.