Jinja2 Changelog
================
-Version 2.5
------------
-(codename not be selected, release date to be announced)
+Version 2.4.2
+-------------
+(bugfix release, release date to be announced)
+
+- improved the sort filter (should have worked like this for a
+ long time) by adding support for case insensitive searches.
+- fixed a bug for getattribute constant folding.
Version 2.4.1
-------------
return sorted(value.items(), key=sort_func)
-def do_sort(value, case_sensitive=False):
- """Sort an iterable. If the iterable is made of strings the second
- parameter can be used to control the case sensitiveness of the
- comparison which is disabled by default.
+def do_sort(value, reverse=False, case_sensitive=False):
+ """Sort an iterable. Per default it sorts ascending, if you pass it
+ true as first argument it will reverse the sorting.
+
+ If the iterable is made of strings the third parameter can be used to
+ control the case sensitiveness of the comparison which is disabled by
+ default.
.. sourcecode:: jinja
return item
else:
sort_func = None
- return sorted(seq, key=sort_func)
+ return sorted(value, key=sort_func, reverse=reverse)
def do_default(value, default_value=u'', boolean=False):
return func(value)
-def do_sort(value, reverse=False):
- """Sort a sequence. Per default it sorts ascending, if you pass it
- true as first argument it will reverse the sorting.
- """
- return sorted(value, reverse=reverse)
-
-
@environmentfilter
def do_groupby(environment, value, attribute):
"""Group a sequence of objects by a common attribute.
'sum': sum,
'abs': abs,
'round': do_round,
- 'sort': do_sort,
'groupby': do_groupby,
'safe': do_mark_safe,
'xmlattr': do_xmlattr
tmpl = env.from_string('{{ [2, 3, 1]|sort }}|{{ [2, 3, 1]|sort(true) }}')
assert tmpl.render() == '[1, 2, 3]|[3, 2, 1]'
+ def test_sort2(self):
+ tmpl = env.from_string('{{ "".join(["c", "A", "b", "D"]|sort(false, true)) }}')
+ assert tmpl.render() == 'AbcD'
+
def test_groupby(self):
tmpl = env.from_string('''
{%- for grouper, list in [{'foo': 1, 'bar': 2},