[Zope] title property/function
Casey Duncan
c.duncan@nlada.org
Fri, 19 Oct 2001 16:50:31 -0400
On Friday 19 October 2001 04:29 pm, Laurie Nason allegedly wrote:
> 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!
>
> Any ideas?
>
> Laurie
Try:
return_object.sort(lambda a,b:a.title(a,context.REQUEST)<b.title(b,context.REQUEST))
or possibly just
return_object.sort(lambda a,b:a.title(a)<b.title(b))
depending on what environment title expects. I suspect title is a DTML method from
what you decribe. This whole thing could be simplified by making title a
Pyhon script. Calling DTML directly from Python is a bit weird... If I am wrong and
title already is a Py script, the use:
return_object.sort(lambda a,b:a.title()<b.title())
At any rate the key is the (), which tells Python to call the bugger.
hth,
/---------------------------------------------------\
Casey Duncan, Sr. Web Developer
National Legal Aid and Defender Association
c.duncan@nlada.org
\---------------------------------------------------/