Fixed groupby bare integer. This fixes #40
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 17 Jun 2011 02:13:00 +0000 (04:13 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 17 Jun 2011 02:13:00 +0000 (04:13 +0200)
jinja2/filters.py
jinja2/testsuite/filters.py

index 5b394ded66ae25926f159e21b89f0708533bb689..1ef47f95161b7ef8f07dcd79bc86dc3582f6c985 100644 (file)
@@ -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):
index 5bb6b124722b252fb7e5ff702a36178b201b7efe..aefe76829fa7b0ea9e49db8c1fa4379e3472236b 100644 (file)
@@ -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):