Fixed #539 -- Added support for strides to 'slice' template filter, and made the code more efficient. Thanks, Esaj

git-svn-id: http://code.djangoproject.com/svn/django/trunk@666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-09-23 00:12:24 +00:00
parent a7efb3939f
commit 1a5ada0101
1 changed files with 3 additions and 13 deletions

View File

@ -245,19 +245,9 @@ def slice_(value, arg):
for an introduction.
"""
try:
start, finish = arg.split(':')
except ValueError: # unpack list of wrong size
return value # fail silently but nicely
try:
if start and finish:
return value[int(start):int(finish)]
if start:
return value[int(start):]
if finish:
return value[:int(finish)]
except TypeError:
pass
return value
return value[slice(*[x and int(x) or None for x in arg.split(':')])]
except (ValueError, TypeError):
return value # Fail silently.
def unordered_list(value, _):
"""