Ticket #7501: fixcyclebehaviour.patch
File fixcyclebehaviour.patch, 2.5 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/templates/tests.py
156 156 split = token.split_contents() 157 157 self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")']) 158 158 159 def test_cycle_multiple_render(self): 160 t = template.Template("{% cycle a,b,c as abc %}{% cycle abc %}") 161 c = template.Context({}) 162 print "K", t.render(c), t.render(c) 163 self.assertEqual(t.render(c), t.render(c)) 164 165 t = template.Template("{% for letter in abc %}{% cycle 'd' 'e' 'f' 'g' %}{% endfor %}") 166 c = template.Context({"abc": ("a", "b", "c")}) 167 168 print "S", t.render(c), t.render(c) 169 self.assertEqual(t.render(c), t.render(c)) 170 159 171 def test_url_reverse_no_settings_module(self): 160 172 # Regression test for #9005 161 173 from django.template import Template, Context, TemplateSyntaxError -
django/template/defaulttags.py
39 39 40 40 class CycleNode(Node): 41 41 def __init__(self, cyclevars, variable_name=None): 42 self.cycle_ iter = itertools_cycle(cyclevars)42 self.cycle_vars = cyclevars 43 43 self.variable_name = variable_name 44 self._first = False 44 45 45 46 def render(self, context): 47 if self._first: 48 self.cycle_iter = itertools_cycle(self.cycle_vars) 46 49 value = self.cycle_iter.next().resolve(context) 47 50 if self.variable_name: 48 51 context[self.variable_name] = value 52 self._first = False 49 53 return value 50 54 55 def reset(self): 56 self._first = True 57 51 58 class DebugNode(Node): 52 59 def render(self, context): 53 60 from pprint import pformat -
django/template/__init__.py
175 175 176 176 def render(self, context): 177 177 "Display stage -- can be called many times" 178 for n in self.nodelist.get_nodes_by_type(Node): 179 try: 180 n.reset() 181 except: 182 pass 178 183 return self.nodelist.render(context) 179 184 180 185 def compile_string(template_string, origin):