Ticket #2743: cycle.patch
File cycle.patch, 1.9 KB (added by , 18 years ago) |
---|
-
django/template/defaulttags.py
13 13 return '' 14 14 15 15 class CycleNode(Node): 16 def __init__(self, cyclevars ):16 def __init__(self, cyclevars, variable_name = None): 17 17 self.cyclevars = cyclevars 18 18 self.cyclevars_len = len(cyclevars) 19 19 self.counter = -1 20 self.variable_name = variable_name 20 21 21 22 def render(self, context): 22 23 self.counter += 1 23 return self.cyclevars[self.counter % self.cyclevars_len] 24 value = self.cyclevars[self.counter % self.cyclevars_len] 25 if self.variable_name : 26 context [self.variable_name] = value 27 return value 24 28 25 29 class DebugNode(Node): 26 30 def render(self, context): … … 385 389 raise TemplateSyntaxError("Second 'cycle' argument must be 'as'") 386 390 cyclevars = [v for v in args[1].split(",") if v] # split and kill blanks 387 391 name = args[3] 388 node = CycleNode(cyclevars )392 node = CycleNode(cyclevars, name) 389 393 390 394 if not hasattr(parser, '_namedCycleNodes'): 391 395 parser._namedCycleNodes = {} -
tests/regressiontests/templates/tests.py
187 187 'cycle05': ('{% cycle %}', {}, template.TemplateSyntaxError), 188 188 'cycle06': ('{% cycle a %}', {}, template.TemplateSyntaxError), 189 189 'cycle07': ('{% cycle a,b,c as foo %}{% cycle bar %}', {}, template.TemplateSyntaxError), 190 'cycle08': ('{% cycle a,b,c as foo %}{% cycle foo %}{{ foo }}{{ foo }}{% cycle foo %}{{ foo }}', {}, "abbbcc"), 190 191 191 192 ### EXCEPTIONS ############################################################ 192 193