Skip to content
This repository
Browse code

Fixed groupby bare integer. This fixes #40

  • Loading branch information...
commit 1655b4e4c1dbd213657f3e6aca28f083f7be62af 1 parent 18286b6
Armin Ronacher authored June 17, 2011
2  jinja2/filters.py
@@ -53,7 +53,7 @@ def make_attrgetter(environment, attribute):
53 53
     passed object with the rules of the environment.  Dots are allowed
54 54
     to access attributes of attributes.
55 55
     """
56  
-    if '.' not in attribute:
  56
+    if not isinstance(attribute, basestring) or '.' not in attribute:
57 57
         return lambda x: environment.getitem(x, attribute)
58 58
     attribute = attribute.split('.')
59 59
     def attrgetter(item):
7  jinja2/testsuite/filters.py
@@ -288,6 +288,13 @@ def test_groupby(self):
288 288
             ""
289 289
         ]
290 290
 
  291
+    def test_groupby_tuple_index(self):
  292
+        tmpl = env.from_string('''
  293
+        {%- for grouper, list in [('a', 1), ('a', 2), ('b', 1)]|groupby(0) -%}
  294
+            {{ grouper }}{% for x in list %}:{{ x.1 }}{% endfor %}|
  295
+        {%- endfor %}''')
  296
+        assert tmpl.render() == 'a:1:2|b:1|'
  297
+
291 298
     def test_groupby_multidot(self):
292 299
         class Date(object):
293 300
             def __init__(self, day, month, year):

0 notes on commit 1655b4e

Please sign in to comment.
Something went wrong with that request. Please try again.