Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed groupby bare integer. This fixes #40

  • Loading branch information...
commit 1655b4e4c1dbd213657f3e6aca28f083f7be62af 1 parent 18286b6
@mitsuhiko authored
Showing with 8 additions and 1 deletion.
  1. +1 −1  jinja2/filters.py
  2. +7 −0 jinja2/testsuite/filters.py
View
2  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):
View
7 jinja2/testsuite/filters.py
@@ -288,6 +288,13 @@ def test_groupby(self):
""
]
+ 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):
Please sign in to comment.
Something went wrong with that request. Please try again.