[Zope] sifting through python sub-objects

Dieter Maurer dieter@handshake.de
Tue, 20 Jun 2000 22:05:32 +0200 (CEST)


ed colmar writes:
 > I've succesfully gotten the catalog to work (thanks everyone!), but in
 > doing so, I've created a problem.  Squishdot uses this code like this in
 > order to add an item:
 > 
 >         id=self.createId()    # make a datestamp id
 >         msg=PromoterPost(id,title) 
 >         msg=msg.__of__(self)  #  ???
 >         self.setItem(id,msg)  #  set the item
 > 
 > This code is incompatible with the catalog.  As far as I can tell because
 > The catalog likes to see id's as strings,
As far as I know the sources, ZCatalog expects its fields to
be either simple objects (strings, numbers, dates, ...) or
be callable with the result a simple object.
 > but I don't think the object gets
 > completely added to the zope fs either.
What does that mean?

 > After changing the code that does
 > the adding to the zope fs everything related to the catalog seems good.
 > Here's the new code:
 > 
 >         ob=PromoterPost(id,title)
 >         ob.id = id
 >         ob.title = title
 > 
 >         self._setObject(id,ob)
 >         self.getCatalog().catalog_object(ob,id)
I would expect that "_setObject" stores the association
"id -> ob" somewhere. I assume, a Python dictionary is
used for this purpose.

Squishdot probably uses a BTree instead, because is can
handle a big number of content objects more efficiently
than a Python dict.

 > So here's the problem, the methods that squishdot uses to locate
 > sub-objects relies on a BTree() type method, called "data", and is used by
 > a few methods like this:
 > 
 >     def objectValues(self):
 >         """ return list of subobjects """
 >         return map(lambda x, p=self: x.__of__(p), self.data.map(self.ids))
 >  or 
 > 
 >     def is_local_user(self, thisuser):
 >         """ returns true with ID if user is a local user
 >             based on rev_id_list in squishdot
 >         """
 >         rlist = map(None,self.ids)
 >         rlist = filter(lambda x,p=self : p.data[x].validated, rlist)
 >         rlist = filter(lambda x,p=self : p.data[x].meta_type ==
 > 'SRPersonPost', rlist)
 >         rlist = filter(lambda x,p=self,s=thisuser : p.data[x].title == s,
 > rlist)
 >         return rlist
 > 
 > 	Neither return any results, becuase in the new code, the data object is
 > not getting updated.  Do I need to keep a record of all the ids like
 > squishdot does, or can I leave that up to zope?
Use the BTree, if you want to use major parts of Squishdot.

Otherwise, you must use methods from the same place you have
taken "_setObject" from. I am sure, the class will have
"objectValues" and "objectIds", too.
And I expect, there will be some form of "_getObject" (probably
named differently) to access the object corresponding to an "id".
Have a look at the Object Reference in the Zope documentation.


Dieter

 > 
 > 	It seems like there should be an easier way than "self.data" to do this...  
 > 
 > 	Any ideas?
 > 
 >