Django

Code

Changeset 6636

Show
Ignore:
Timestamp:
11/02/07 21:04:59 (10 months ago)
Author:
gwilson
Message:

Made use of itertools.cycle for the cycle template tag.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaulttags.py

    r6571 r6636  
    11"Default tags used by the template system, available to all templates." 
     2 
     3from itertools import cycle as itertools_cycle 
    24 
    35from django.template import Node, NodeList, Template, Context, Variable 
     
    2325class CycleNode(Node): 
    2426    def __init__(self, cyclevars, variable_name=None): 
    25         self.cyclevars = cyclevars 
    26         self.cyclevars_len = len(cyclevars) 
    27         self.counter = -1 
     27        self.cycle_iter = itertools_cycle(cyclevars) 
    2828        self.variable_name = variable_name 
    2929 
    3030    def render(self, context): 
    31         self.counter += 1 
    32         value = self.cyclevars[self.counter % self.cyclevars_len] 
     31        value = self.cycle_iter.next() 
    3332        value = Variable(value).resolve(context) 
    3433        if self.variable_name: