Sorting in Python Script
In DTML I do this: <dtml-in "folder.objectValues('Meta Type')"> And in Python Script: objlist = context.folder.objectValues('Meta Type') BUT! Now this I only know how to do in DTML 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) but no success! Can somebody explain how to get all the luxury of DTML-IN in Python Scripts?? <BR> Peter
I have tried objlist.sort('bobobase_modification_time') and objlist.sort(bobobase_modification_time)
This is really a Python Question. Try this: def sortByDate(x, y): return cmp(x.bobobase_modification_time, y.bobobase_modification_time) objlist.sort(sortByDate) Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management
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.
participants (3)
-
Oleg Broytmann -
Peter Bengtsson -
Stephan Richter