1 ##parameters=objects, sorted_field, sorted_dir
3 if not objects
: return []
5 mtool
= context
.portal_membership
6 wftool
= context
.portal_workflow
8 functions
= {'title' : lambda ob
: ob
.title_or_id().lower() ,
9 'date' : lambda ob
: ob
.modified() ,
10 'submitTime' : lambda ob
: wftool
.getInfoFor(ob
, 'time'),
11 'actor' : lambda ob
: mtool
.getMemberFullNameById(wftool
.getInfoFor(ob
, 'actor')),
12 'Creator' : lambda ob
: mtool
.getMemberFullNameById(ob
.Creator()),
13 'review_state' : lambda ob
: wftool
.getInfoFor(ob
, 'review_state', ''),
17 sort_func
= functions
.get(sorted_field
, None)
18 if sort_func
is None :
19 if hasattr(objects
[0], sorted_field
):
20 sort_func
= callable(getattr(objects
[0], sorted_field
)) and (lambda ob
: getattr(ob
, sorted_field
)()) or (lambda ob
: getattr(ob
, sorted_field
))
25 objects
.sort(sorted_dir
== 'down' and (lambda a
,b
: cmp(sort_func(b
), sort_func(a
))) or (lambda a
,b
: cmp(sort_func(a
), sort_func(b
))))