Author: Alex
Date: 2011-01-25 21:34:16 -0600 (Tue, 25 Jan 2011)
New Revision: 15316

Modified:
   django/trunk/django/template/defaultfilters.py
Log:
Fixed #13828 -- DRY'd up the dictsort(reversed) filters, will speed them up as 
well.

Modified: django/trunk/django/template/defaultfilters.py
===================================================================
--- django/trunk/django/template/defaultfilters.py      2011-01-26 03:23:59 UTC 
(rev 15315)
+++ django/trunk/django/template/defaultfilters.py      2011-01-26 03:34:16 UTC 
(rev 15316)
@@ -460,10 +460,7 @@
     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 @@
     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):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to