diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 9eae75b8ef..36b07fa7b3 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -84,19 +84,16 @@ class FirstOfNode(Node): 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 "" % \ (', '.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 @@ class ForNode(Node): 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):