From 1a5ada01010a7b9472c46d46f5c6d2ddcdcb1226 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 23 Sep 2005 00:12:24 +0000 Subject: [PATCH] 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 --- django/core/defaultfilters.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/django/core/defaultfilters.py b/django/core/defaultfilters.py index ff55219f0b..eb3ec11c95 100644 --- a/django/core/defaultfilters.py +++ b/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, _): """