[Zope] Sorting in python script
Oleg Broytmann
Oleg Broytmann <phd@phd.pp.ru>
Wed, 24 Oct 2001 19:40:42 +0400
On Wed, Oct 24, 2001 at 01:29:45PM +0200, Gitte Wange wrote:
> when you have a dtml-in tag you can set sort=attribute
>
> But how do you do that in a python script?
> You can't do:
> for item in folder.objectValues('lala') sort='something':
Something like this:
from DTML import SortEx # I m not sure about "DTML", may be "from DT_Util" or such
for item in SortEx(folder.objectValues('lala'), (("something",),))
The second rgument is a tuple of tuples that lists sort prameters. Every
inner tuple constructed as follows:
(attribute, function, order)
where "attribute" is an attribute of the object you want to sort on,
"function" is a comparison function, and "order" is "ASC" or "DESC". You my
use predefined comparison functions "cmp", "locle" (alias "strcoll"),
"nocase" and "locale_nocase" (alias "locale_strcoll"). You may omit sort
order (default is "ASC"), or you may omit both function (default is "cmp")
and sort order. You cannot omit function, but use sort order; use "cmp" as
a function.
Oleg.
--
Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.