mirror of https://github.com/django/django.git
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:
parent
a7efb3939f
commit
1a5ada0101
|
@ -245,19 +245,9 @@ def slice_(value, arg):
|
||||||
for an introduction.
|
for an introduction.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
start, finish = arg.split(':')
|
return value[slice(*[x and int(x) or None for x in arg.split(':')])]
|
||||||
except ValueError: # unpack list of wrong size
|
except (ValueError, TypeError):
|
||||||
return value # fail silently but nicely
|
return value # Fail silently.
|
||||||
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
|
|
||||||
|
|
||||||
def unordered_list(value, _):
|
def unordered_list(value, _):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue