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

Pascal Samuzeau samuzeau@oreka.com
Wed, 20 Nov 2002 18:01:47 +0100


Hi Gitte,                                                             
                                                                      
great, I've got it.                                                   
                                                                      
Thanks a lot.                                                         
                                                                      
Cheers                                                                
PS                                                                    
-------------------                                                   
> 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                                 
>                                                                     
Cordialement                                                          
PS                                                                    
--------------------------------------------------                    
Oreka ! Nous sommes l'internet moins cher !                           
Surfez 25% moins cher avec http://www.oreka.com