From: Armin Ronacher Date: Fri, 17 Jun 2011 02:13:00 +0000 (+0200) Subject: Fixed groupby bare integer. This fixes #40 X-Git-Tag: 2.6~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1655b4e4c1dbd213657f3e6aca28f083f7be62af;p=thirdparty%2Fjinja.git Fixed groupby bare integer. This fixes #40 --- diff --git a/jinja2/filters.py b/jinja2/filters.py index 5b394ded..1ef47f95 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -53,7 +53,7 @@ def make_attrgetter(environment, attribute): passed object with the rules of the environment. Dots are allowed to access attributes of attributes. """ - if '.' not in attribute: + if not isinstance(attribute, basestring) or '.' not in attribute: return lambda x: environment.getitem(x, attribute) attribute = attribute.split('.') def attrgetter(item): diff --git a/jinja2/testsuite/filters.py b/jinja2/testsuite/filters.py index 5bb6b124..aefe7682 100644 --- a/jinja2/testsuite/filters.py +++ b/jinja2/testsuite/filters.py @@ -288,6 +288,13 @@ class FilterTestCase(JinjaTestCase): "" ] + def test_groupby_tuple_index(self): + tmpl = env.from_string(''' + {%- for grouper, list in [('a', 1), ('a', 2), ('b', 1)]|groupby(0) -%} + {{ grouper }}{% for x in list %}:{{ x.1 }}{% endfor %}| + {%- endfor %}''') + assert tmpl.render() == 'a:1:2|b:1|' + def test_groupby_multidot(self): class Date(object): def __init__(self, day, month, year):