Permalink
Browse files

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.

--HG--
branch : trunk
  • Loading branch information...
1 parent 5a5ce73 commit 737954909febeabbabda84b933fa78066bb5c3ef @mitsuhiko mitsuhiko committed May 23, 2010
Showing with 19 additions and 16 deletions.
  1. +7 −3 CHANGES
  2. +8 −13 jinja2/filters.py
  3. +4 −0 jinja2/testsuite/filters.py
View
10 CHANGES
@@ -1,9 +1,13 @@
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
-------------
View
@@ -176,10 +176,13 @@ def sort_func(item):
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
@@ -194,7 +197,7 @@ def sort_func(item):
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):
@@ -564,13 +567,6 @@ def do_round(value, precision=0, method='common'):
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.
@@ -723,7 +719,6 @@ def do_attr(environment, obj, name):
'sum': sum,
'abs': abs,
'round': do_round,
- 'sort': do_sort,
'groupby': do_groupby,
'safe': do_mark_safe,
'xmlattr': do_xmlattr
@@ -227,6 +227,10 @@ def test_sort1(self):
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},

0 comments on commit 7379549

Please sign in to comment.