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
This commit is contained in:
parent
b4bf635cea
commit
561af6417e
|
@ -460,10 +460,7 @@ def dictsort(value, arg):
|
||||||
Takes a list of dicts, returns that list sorted by the property given in
|
Takes a list of dicts, returns that list sorted by the property given in
|
||||||
the argument.
|
the argument.
|
||||||
"""
|
"""
|
||||||
var_resolve = Variable(arg).resolve
|
return sorted(value, key=Variable(arg).resolve)
|
||||||
decorated = [(var_resolve(item), item) for item in value]
|
|
||||||
decorated.sort()
|
|
||||||
return [item[1] for item in decorated]
|
|
||||||
dictsort.is_safe = False
|
dictsort.is_safe = False
|
||||||
|
|
||||||
def dictsortreversed(value, arg):
|
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
|
Takes a list of dicts, returns that list sorted in reverse order by the
|
||||||
property given in the argument.
|
property given in the argument.
|
||||||
"""
|
"""
|
||||||
var_resolve = Variable(arg).resolve
|
return sorted(value, key=Variable(arg).resolve, reverse=True)
|
||||||
decorated = [(var_resolve(item), item) for item in value]
|
|
||||||
decorated.sort()
|
|
||||||
decorated.reverse()
|
|
||||||
return [item[1] for item in decorated]
|
|
||||||
dictsortreversed.is_safe = False
|
dictsortreversed.is_safe = False
|
||||||
|
|
||||||
def first(value):
|
def first(value):
|
||||||
|
|
Loading…
Reference in New Issue