[Zope] Search a Catalog in Python

Chris Withers lists at simplistix.co.uk
Wed Mar 17 04:08:28 EST 2004


Max M wrote:

> Dragos Chirila wrote:
> 
>> Hi
>>
>> I am doing something similarly.
>>
>>     def __searchCatalog(self, p_criteria):
>>         """Search catalog"""
>>         return self.__catalog(p_criteria)
>>
>> This returns a list of mybrains objects.
>>
>>     def __getFoundObjects(self, p_list):
>>         """gets objects from catalog results"""
>>         return map(self.__catalog.getobject, map(getattr, p_list,
>> ('data_record_id_',)*len(p_list)))
>>
>> It gets a list of mybrains objects and returns a list of zope objects.
> 
> Hmm! I think that is a questionable approach.

Indeed, yuk! Don't really know why you're hiding your catalog away in __catalog. 
Why not just make your code ObjectManager or Folderish and put your catalog in 
there?

As for "getting found objects":

return [brain.getObject() for brain in self.__catalog(p_criteria)]

...seems a LOT nicer to me.

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk




More information about the Zope mailing list