[Zope-CMF] Syntax of using portal_catalog in python scripting

Gitte Wange gitte@mmmanager.org
20 Nov 2002 17:29:22 +0100


On Wed, 2002-11-20 at 17:24, Pascal Samuzeau wrote:
> Hi,                                                                   
>                                                                       
> I have tried in many ways but I can't found the solution to get my    
> object throught portal_catalog in a python's script                   
>                                                                       
> I have tried, the syntax that I catched on this list.                 
>                                                                       
> item_brain = portal_catalog(id=this_id)                               
> ob = item_brain.getObject()                                           
>                                                                       
> But it raises me the error :                                          
>                                                                       
> Error Type: AttributeError                                            
> Error Value: LazyMap instance has no attribute 'getObject'            
>                                                                       
> What's happen ?                                                       
>                                                                       
> Cheers                                                                
> PS                                                                    

Hello Pascal,

portal_catalog is returning a list of brains ...
So you are querying a list instead of a brain.
Instead try with:

item_brain = portal_catalog(id=this_is)[0]
(returning first brain in list)

or do a fail_safe one:
result = portal_catalog(id=this_is)
if result:
    item_brain = result[0]

-- 
Gitte Wange
Technical Manager

Email: gitte@mmmanager.org
Web: http://www.mmmanager.org
Tlf: +45 36 46 20 02

After 1.5 years of Python, I'm still discovering 
richness (and still unable to understand what the 
hell Jim Fulton is talking about).

    -- Gordon McMillan, 13 Mar 1998