Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15572 - include with "only" option discards context properties…

… (such as autoescape)

Thanks to dfoerster for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15795 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e9d27639470d2e76ce51a2522aedc69ff912de3e 1 parent 3349b95
Luke Plant authored March 10, 2011
8  django/template/context.py
@@ -99,6 +99,14 @@ def update(self, other_dict):
99 99
         self.dicts.append(other_dict)
100 100
         return other_dict
101 101
 
  102
+    def new(self, values=None):
  103
+        """
  104
+        Returns a new Context with the same 'autoescape' value etc, but with
  105
+        only the values given in 'values' stored.
  106
+        """
  107
+        return self.__class__(dict_=values, autoescape=self.autoescape,
  108
+                              current_app=self.current_app, use_l10n=self.use_l10n)
  109
+
102 110
 class RenderContext(BaseContext):
103 111
     """
104 112
     A stack container for storing Template state.
2  django/template/loader_tags.py
@@ -136,7 +136,7 @@ def render_template(self, template, context):
136 136
         values = dict([(name, var.resolve(context)) for name, var
137 137
                        in self.extra_context.iteritems()])
138 138
         if self.isolated_context:
139  
-            return template.render(Context(values))
  139
+            return template.render(context.new(values))
140 140
         context.update(values)
141 141
         output = template.render(context)
142 142
         context.pop()
4  tests/regressiontests/templates/tests.py
@@ -1031,6 +1031,10 @@ def get_template_tests(self):
1031 1031
             'include11': ('{% include "basic-syntax03" only with second=2 %}', {'first': '1'}, (' --- 2', 'INVALID --- 2')),
1032 1032
             'include12': ('{% include "basic-syntax03" with first=1 only %}', {'second': '2'}, ('1 --- ', '1 --- INVALID')),
1033 1033
 
  1034
+            # autoescape context
  1035
+            'include13': ('{% autoescape off %}{% include "basic-syntax03" %}{% endautoescape %}', {'first': '&'}, ('& --- ', '& --- INVALID')),
  1036
+            'include14': ('{% autoescape off %}{% include "basic-syntax03" with first=var1 only %}{% endautoescape %}', {'var1': '&'}, ('& --- ', '& --- INVALID')),
  1037
+
1034 1038
             'include-error01': ('{% include "basic-syntax01" with %}', {}, template.TemplateSyntaxError),
1035 1039
             'include-error02': ('{% include "basic-syntax01" with "no key" %}', {}, template.TemplateSyntaxError),
1036 1040
             'include-error03': ('{% include "basic-syntax01" with dotted.arg="error" %}', {}, template.TemplateSyntaxError),

0 notes on commit e9d2763

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