Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #539 -- Added support for strides to 'slice' template filter, a…

…nd made the code more efficient. Thanks, Esaj

git-svn-id: http://code.djangoproject.com/svn/django/trunk@666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1a5ada01010a7b9472c46d46f5c6d2ddcdcb1226 1 parent a7efb39
@adrianholovaty adrianholovaty authored
Showing with 3 additions and 13 deletions.
  1. +3 −13 django/core/defaultfilters.py
View
16 django/core/defaultfilters.py
@@ -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, _):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.