[Zope] Sorting in Python Script
Oleg Broytmann
Oleg Broytmann <phd@phd.fep.ru>
Thu, 5 Apr 2001 17:54:03 +0400 (MSD)
On Thu, 5 Apr 2001, Peter Bengtsson wrote:
> In DTML I do this:
>
> <dtml-in "folder.objectValues('Meta Type') sort=bobobase_modification_time>
>
> How do I do this in Python Scripts??
>
> I have tried
> objlist.sort('bobobase_modification_time')
> and
> objlist.sort(bobobase_modification_time)
I am working on the generic External Method to do this. There is Zieve
Product for similar things.
But if you want do it yourself (and I recommend to do it) - learn a bit
of Python.
Sequence.sort() accepts a function, that does comparison, so you want
somethimng like this (untested):
def bmt_cmp(object1, object2):
return cmp(object1.bobobase_modification_time(), object2.bobobase_modification_time())
(note - bobobase_modification_time is a function!)
objlist.sort(bmt_cmp)
return objlist
Oleg.
----
Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.