[Zope] title property/function

Thomas B. Passin tpassin@mitretek.org
Fri, 19 Oct 2001 16:57:45 -0400


[Laurie Nason]

> OK guys - here's the problem....
> I have a number of ZClasses, each one has a title property that is
actually
> a function and pulls information from other properties of the ZClass. I
want
> to use this property to sort my tree object. So being the python genius
that
> I am not - I have created a python script to return the branches in the
> correct order sorted by title.
>
> # This is the code that returns objects for the tree view
>
> con=context
> return_object=[]
>
> for obj in con.objectValues(['Folder','Group', 'Project', 'Micrograph',
> 'Microscopy', 'Scan', 'Purification', 'Aliquot', 'Freezing', 'Progress',
> 'Publication', 'Reference', 'Reconstruction', 'Structure', 'CCD']):
>     return_object.append(obj)
>
> return_object.sort(lambda a,b:a.title<b.title)
> return return_object
>
> However, this code does not evaluate the title - but simply returns the
> dtml-if statement and sorts on that.... not what I want!
>

Aside from Zope-specific details, Python sort functions need to return one
of three values: -1 for "less than", 0 for "compares equal", and +1 for
"greater than", not just 0 or 1.

Cheers,

Tom P