Skip to content
Myr

'reverse' option for dictsort

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dick Visser · committed by David Lord · parent 07c0b87 · Browse files · 1 file+5 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−2 removed

  • other:+5 added−2 removed

1 file+5 added−2 removed

modified:jinja2/filters.py+5 added-2 removed
201 unmodified lines
202 for item in _word_beginning_split_re.split(soft_unicode(s))203 if item])204205206def do_dictsort(value, case_sensitive=False, by='key'):206def do_dictsort(value, case_sensitive=False, by='key', reverse=False):207 """Sort a dict and yield (key, value) pairs. Because python dicts are208 unsorted you may want to use this function to order them by either209 key or value:210
1 unmodified line
212213 {% for item in mydict|dictsort %}214 sort the dict by key, case insensitive215216 {% for item in mydict|dictsort(reverse=true) %}217 sort the dict by key, case insensitive, reverse order218219 {% for item in mydict|dictsort(true) %}220 sort the dict by key, case sensitive221222 {% for item in mydict|dictsort(false, 'value') %}
11 unmodified lines
234 if isinstance(value, string_types) and not case_sensitive:235 value = value.lower()236 return value237235 return sorted(value.items(), key=sort_func)238 return sorted(value.items(), key=sort_func, reverse=reverse)239240241@environmentfilter242def do_sort(
944 unmodified lines