Fixed groupby bare integer. This fixes #40
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 @@
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 @@
""
]
+ 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):