Changeset 7756
- Timestamp:
- 06/26/08 00:16:19 (5 months ago)
- Files:
-
- django/trunk/django/template/defaulttags.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/defaulttags.py
r7752 r7756 40 40 class CycleNode(Node): 41 41 def __init__(self, cyclevars, variable_name=None): 42 self.cycle_iter = itertools_cycle( cyclevars)42 self.cycle_iter = itertools_cycle([Variable(v) for v in cyclevars]) 43 43 self.variable_name = variable_name 44 44 45 45 def render(self, context): 46 value = self.cycle_iter.next() 47 value = Variable(value).resolve(context) 46 value = self.cycle_iter.next().resolve(context) 48 47 if self.variable_name: 49 48 context[self.variable_name] = value … … 455 454 <tr class="{% cycle rowcolors %}">...</tr> 456 455 457 You can use any number of values, sep erated by spaces. Commas can also456 You can use any number of values, separated by spaces. Commas can also 458 457 be used to separate values; if a comma is used, the cycle values are 459 458 interpreted as literal strings. … … 462 461 # Note: This returns the exact same node on each {% cycle name %} call; 463 462 # that is, the node object returned from {% cycle a b c as name %} and the 464 # one returned from {% cycle name %} are the exact same object. This463 # one returned from {% cycle name %} are the exact same object. This 465 464 # shouldn't cause problems (heh), but if it does, now you know. 466 465 # 467 # Ugly hack warning: this stuffs the named template dict into parser so466 # Ugly hack warning: This stuffs the named template dict into parser so 468 467 # that names are only unique within each template (as opposed to using 469 468 # a global variable, which would make cycle names have to be unique across … … 484 483 name = args[1] 485 484 if not hasattr(parser, '_namedCycleNodes'): 486 raise TemplateSyntaxError("No named cycles in template." 487 " '%s' is not defined" % name) 485 raise TemplateSyntaxError("No named cycles in template. '%s' is not defined" % name) 488 486 if not name in parser._namedCycleNodes: 489 487 raise TemplateSyntaxError("Named cycle '%s' does not exist" % name)
