Geir, This is something I've just hacked from a longer piece of code, works for me, ymmv def cmpfunc(a,b): a=a[1].aq_explicit b=b[1].aq_explicit ast=getattr(a,'precedence',None) if not ast: ast=getattr(a,'short_title',None) if not ast: ast=a.title_or_id() bst=getattr(b,'precedence',None) if not ast: bst=getattr(b,'short_title',None) if not bst: bst=b.title_or_id() if ast<bst: return -1 elif ast>bst: return 1 else: return 0 def sorted_items(self): items=self.objectItems() # This is laziness on my part. # some of the objects don't have certain properties and I can't be bothered checking ;) try: items.sort(cmpfunc) except: pass return items hth Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Geir Bækholt" <geirh@funcom.com> To: <zope@zope.org> Sent: Tuesday, June 19, 2001 9:29 AM Subject: [Zope] objectValues sorting in pythonscripts ?
Zopatistas,
is there any simple way to sort object instances (as returned from objectValues) on properties like you can with <dtml-in objectValues sort=title>, using a python for/in loop ?
-- Geir Bækholt web-developer/zopatista geirh@funcom.com funcom oslo | webdev-team
<!-- PGPid : 0x90B47B20 -->
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )