Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renamed 'reversed' variable to 'is_reversed' in ForLoop template tag …

…implementation, to avoid potential conflicts with the 'reversed' built-in and to make the code more obvious

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e7b338d10e9a301773f4068b38e907c366d53e83 1 parent abffdf5
@adrianholovaty adrianholovaty authored
Showing with 8 additions and 11 deletions.
  1. +8 −11 django/template/defaulttags.py
View
19 django/template/defaulttags.py
@@ -84,19 +84,16 @@ def render(self, context):
return u''
class ForNode(Node):
- def __init__(self, loopvars, sequence, reversed, nodelist_loop):
+ def __init__(self, loopvars, sequence, is_reversed, nodelist_loop):
self.loopvars, self.sequence = loopvars, sequence
- self.reversed = reversed
+ self.is_reversed = is_reversed
self.nodelist_loop = nodelist_loop
def __repr__(self):
- if self.reversed:
- reversed = ' reversed'
- else:
- reversed = ''
+ reversed_text = self.is_reversed and ' reversed' or ''
return "<For Node: for %s in %s, tail_len: %d%s>" % \
(', '.join(self.loopvars), self.sequence, len(self.nodelist_loop),
- reversed)
+ reversed_text)
def __iter__(self):
for node in self.nodelist_loop:
@@ -125,7 +122,7 @@ def render(self, context):
if not hasattr(values, '__len__'):
values = list(values)
len_values = len(values)
- if self.reversed:
+ if self.is_reversed:
values = reversed(values)
unpack = len(self.loopvars) > 1
for i, item in enumerate(values):
@@ -619,8 +616,8 @@ def do_for(parser, token):
raise TemplateSyntaxError("'for' statements should have at least four"
" words: %s" % token.contents)
- reversed = bits[-1] == 'reversed'
- in_index = reversed and -3 or -2
+ is_reversed = bits[-1] == 'reversed'
+ in_index = is_reversed and -3 or -2
if bits[in_index] != 'in':
raise TemplateSyntaxError("'for' statements should use the format"
" 'for x in y': %s" % token.contents)
@@ -634,7 +631,7 @@ def do_for(parser, token):
sequence = parser.compile_filter(bits[in_index+1])
nodelist_loop = parser.parse(('endfor',))
parser.delete_first_token()
- return ForNode(loopvars, sequence, reversed, nodelist_loop)
+ return ForNode(loopvars, sequence, is_reversed, nodelist_loop)
do_for = register.tag("for", do_for)
def do_ifequal(parser, token, negate):
Please sign in to comment.
Something went wrong with that request. Please try again.