[Zope] Sorting on 2 or more properties

Michael Long mlong@datalong.com
21 Apr 2003 12:23:17 -0400


Casey, thanks for the snippet of code. It solves the problem perfectly.

-Mike

On Mon, 2003-04-21 at 10:31, Casey Duncan wrote:
> You could write a general purpose sorting script as follows:
> 
> ##Script (Python) "multiSort"
> ##parameters=objects, *sort_attrs
> ##title=Sort a list of objects by one or more of their attributes
> 
> results = []
> for object in objects:
>     row = [getattr(object, attr) for attr in sort_attrs]
>     row.append(object)
>     results.append(tuple(row))
> results.sort()
> return [row[-1] for row in results]
> 
> hth,
> 
> -Casey
-- 
Michael Long <mlong@datalong.com>