From 30ffab1d93c5b02654cec32690c2138b6899df0f Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Jul 2007 20:51:47 +0200 Subject: [PATCH] [svn] fixed groupby (sorted has some weird behavior Oo) --HG-- branch : trunk --- jinja/filters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 -- 2.26.2