Ajout fonction utilitaire pour encoder de manière sécurisé les en-tête des mails.
[Plinn.git] / skins / generic / sort_folder_contents.py
1 ##parameters=objects, sorted_field, sorted_dir
2
3 if not objects : return []
4
5 mtool = context.portal_membership
6 wftool = context.portal_workflow
7
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', ''),
14 }
15
16
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))
21 else :
22 return objects
23
24
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))))
26 return objects