diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-10 03:11:10 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-10 03:11:10 +0000 |
| commit | 03ecc00f6ea756d4659b4cacab3eb6e7405e49e0 (patch) | |
| tree | 9a159ed96c3ef3cae3f00ff3d50501470df725a3 | |
| parent | a33fb695e37c921d2bc0ffe3b011ad830f4bea56 (diff) | |
Fixed #4462 -- Use builtin reversed() function when available (in "for" tag).
Thanks, Brian Harring.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5454 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/template/defaulttags.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 4f232f0c70..6a6665a445 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -7,6 +7,14 @@ from django.conf import settings import sys import re +if not hasattr(__builtins__, 'reversed'): + # For Python 2.3. + # From http://www.python.org/doc/current/tut/node11.html + def reversed(data): + for index in xrange(len(data)-1, -1, -1): + yield data[index] + + register = Library() class CommentNode(Node): @@ -103,11 +111,7 @@ class ForNode(Node): values = list(values) len_values = len(values) if self.reversed: - # From http://www.python.org/doc/current/tut/node11.html - def reverse(data): - for index in range(len(data)-1, -1, -1): - yield data[index] - values = reverse(values) + values = reversed(values) unpack = len(self.loopvars) > 1 for i, item in enumerate(values): context['forloop'] = { |
