From 561af6417e1c8232904b726fb0219cc0b7c2e71d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 26 Jan 2011 03:34:16 +0000 Subject: [PATCH] Fixed #13828 -- DRY'd up the dictsort(reversed) filters, will speed them up as well. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15316 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/defaultfilters.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 8fabef642f..b2aa38e50a 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -460,10 +460,7 @@ def dictsort(value, arg): Takes a list of dicts, returns that list sorted by the property given in the argument. """ - var_resolve = Variable(arg).resolve - decorated = [(var_resolve(item), item) for item in value] - decorated.sort() - return [item[1] for item in decorated] + return sorted(value, key=Variable(arg).resolve) dictsort.is_safe = False def dictsortreversed(value, arg): @@ -471,11 +468,7 @@ def dictsortreversed(value, arg): Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument. """ - var_resolve = Variable(arg).resolve - decorated = [(var_resolve(item), item) for item in value] - decorated.sort() - decorated.reverse() - return [item[1] for item in decorated] + return sorted(value, key=Variable(arg).resolve, reverse=True) dictsortreversed.is_safe = False def first(value):