From 1655b4e4c1dbd213657f3e6aca28f083f7be62af Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Fri, 17 Jun 2011 04:13:00 +0200 Subject: [PATCH] Fixed groupby bare integer. This fixes #40 --- jinja2/filters.py | 2 +- jinja2/testsuite/filters.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jinja2/filters.py b/jinja2/filters.py index 5b394de..1ef47f9 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 5bb6b12..aefe768 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): -- 2.26.2