Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13828 -- DRY'd up the dictsort(reversed) filters, will speed t…

…hem up as well.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15316 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 561af6417e1c8232904b726fb0219cc0b7c2e71d 1 parent b4bf635
Alex Gaynor authored January 26, 2011

Showing 1 changed file with 2 additions and 9 deletions. Show diff stats Hide diff stats

  1. 11  django/template/defaultfilters.py
11  django/template/defaultfilters.py
@@ -460,10 +460,7 @@ def dictsort(value, arg):
460 460
     Takes a list of dicts, returns that list sorted by the property given in
461 461
     the argument.
462 462
     """
463  
-    var_resolve = Variable(arg).resolve
464  
-    decorated = [(var_resolve(item), item) for item in value]
465  
-    decorated.sort()
466  
-    return [item[1] for item in decorated]
  463
+    return sorted(value, key=Variable(arg).resolve)
467 464
 dictsort.is_safe = False
468 465
 
469 466
 def dictsortreversed(value, arg):
@@ -471,11 +468,7 @@ def dictsortreversed(value, arg):
471 468
     Takes a list of dicts, returns that list sorted in reverse order by the
472 469
     property given in the argument.
473 470
     """
474  
-    var_resolve = Variable(arg).resolve
475  
-    decorated = [(var_resolve(item), item) for item in value]
476  
-    decorated.sort()
477  
-    decorated.reverse()
478  
-    return [item[1] for item in decorated]
  471
+    return sorted(value, key=Variable(arg).resolve, reverse=True)
479 472
 dictsortreversed.is_safe = False
480 473
 
481 474
 def first(value):

0 notes on commit 561af64

Please sign in to comment.
Something went wrong with that request. Please try again.