From: Armin Ronacher Date: Tue, 10 Jul 2007 18:51:47 +0000 (+0200) Subject: [svn] fixed groupby (sorted has some weird behavior Oo) X-Git-Tag: 2.0rc1~282 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=30ffab1d93c5b02654cec32690c2138b6899df0f;p=jinja2.git [svn] fixed groupby (sorted has some weird behavior Oo) --HG-- branch : trunk --- diff --git a/jinja/filters.py b/jinja/filters.py index 6407827..3551c57 100644 --- a/jinja/filters.py +++ b/jinja/filters.py @@ -10,6 +10,7 @@ """ import re from random import choice +from operator import itemgetter from urllib import urlencode, quote from jinja.utils import urlize, escape, reversed, sorted, groupby from jinja.datastructure import TemplateData @@ -877,10 +878,11 @@ def do_groupby(attribute): """ def wrapped(env, context, value): expr = lambda x: env.get_attribute(x, attribute) - return [{ + return sorted([{ 'grouper': a, 'list': list(b) - } for a, b in sorted(groupby(sorted(value, key=expr), expr))] + } for a, b in groupby(sorted(value, key=expr), expr)], + key=itemgetter('grouper')) return wrapped