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 -->
Sad to say that you have to use another module to do that. Download SortEx.py (search for SortEx) and create an External Method instance in the root folder (you'll be using this often). Instructions comes with the module. Peter
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 )
On Tue, 19 Jun 2001, Peter Bengtsson wrote:
Sad to say that you have to use another module to do that. Download SortEx.py (search for SortEx) and create an External Method instance in the root folder (you'll be using this often).
http://www.zope.org/Members/phd/Sort/ The code was incorporated into Zope 2.4 (now in alpha stage), so soon you'll don't need to install it. It is going straight into dtml-in tag. Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
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 )
participants (4)
-
Geir Bækholt -
Oleg Broytmann -
Peter Bengtsson -
Phil Harris