diff options
| author | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-11-03 02:04:59 +0000 |
|---|---|---|
| committer | Gary Wilson Jr <gary.wilson@gmail.com> | 2007-11-03 02:04:59 +0000 |
| commit | 2a48fc5007b9fc04f6483ddf022d504bd11e0826 (patch) | |
| tree | f03be0abe307eac78247f67f16fb9367fe42d1da | |
| parent | 5997cb8ad491f250bb0ab6de8f4867af7492aadb (diff) | |
Made use of `itertools.cycle` for the `cycle` template tag.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6636 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/template/defaulttags.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 2ba23a0465..927667c812 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -1,5 +1,7 @@ "Default tags used by the template system, available to all templates." +from itertools import cycle as itertools_cycle + from django.template import Node, NodeList, Template, Context, Variable from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END from django.template import get_library, Library, InvalidTemplateLibrary @@ -22,14 +24,11 @@ class CommentNode(Node): class CycleNode(Node): def __init__(self, cyclevars, variable_name=None): - self.cyclevars = cyclevars - self.cyclevars_len = len(cyclevars) - self.counter = -1 + self.cycle_iter = itertools_cycle(cyclevars) self.variable_name = variable_name def render(self, context): - self.counter += 1 - value = self.cyclevars[self.counter % self.cyclevars_len] + value = self.cycle_iter.next() value = Variable(value).resolve(context) if self.variable_name: context[self.variable_name] = value |
