diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 4b72009..c4a3c02 100644
a
|
b
|
striptags = stringfilter(striptags)
|
459 | 459 | # LISTS # |
460 | 460 | ################### |
461 | 461 | |
462 | | def dictsort(value, arg): |
| 462 | def _dictsort(value, arg, reverse=False): |
463 | 463 | """ |
464 | 464 | Takes a list of dicts, returns that list sorted by the property given in |
465 | 465 | the argument. |
| 466 | The returned list will be in reverse order if `reverse` is `True`. |
466 | 467 | """ |
467 | 468 | var_resolve = Variable(arg).resolve |
468 | | decorated = [(var_resolve(item), item) for item in value] |
469 | | decorated.sort() |
470 | | return [item[1] for item in decorated] |
| 469 | value.sort(key=lambda item: var_resolve(item), reverse=reverse) |
| 470 | return value |
| 471 | |
| 472 | def dictsort(value, arg): |
| 473 | """ |
| 474 | Takes a list of dicts, returns that list sorted by the property given in |
| 475 | the argument. |
| 476 | """ |
| 477 | return _dictsort(value, arg, reverse=False) |
471 | 478 | dictsort.is_safe = False |
472 | 479 | |
473 | 480 | def dictsortreversed(value, arg): |
… |
… |
def dictsortreversed(value, arg):
|
475 | 482 | Takes a list of dicts, returns that list sorted in reverse order by the |
476 | 483 | property given in the argument. |
477 | 484 | """ |
478 | | var_resolve = Variable(arg).resolve |
479 | | decorated = [(var_resolve(item), item) for item in value] |
480 | | decorated.sort() |
481 | | decorated.reverse() |
482 | | return [item[1] for item in decorated] |
| 485 | return _dictsort(value, arg, reverse=True) |
483 | 486 | dictsortreversed.is_safe = False |
484 | 487 | |
485 | 488 | def first(value): |