[Zope] objectValues sorting in pythonscripts ?

Phil Harris phil.harris@zope.co.uk
Tue, 19 Jun 2001 10:01:46 +0100


Geir,

This is something I've just hacked from a longer piece of code, works for
me, ymmv

def cmpfunc(a,b):
    a=3Da[1].aq_explicit
    b=3Db[1].aq_explicit
    ast=3Dgetattr(a,'precedence',None)
    if not ast:
        ast=3Dgetattr(a,'short_title',None)
    if not ast:
        ast=3Da.title_or_id()
    bst=3Dgetattr(b,'precedence',None)
    if not ast:
        bst=3Dgetattr(b,'short_title',None)
    if not bst:
        bst=3Db.title_or_id()

    if ast<bst:
        return -1
    elif ast>bst:
        return 1
    else:
        return 0

def sorted_items(self):
    items=3Dself.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=E6kholt" <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=3Dtitle>,  using a python for/in lo=
op ?
>
>
> --
> Geir B=E6kholt                   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 )