[Zope] Acquiring parent objects through BTrees

Dieter Maurer dieter@handshake.de
Wed, 15 Aug 2001 21:52:58 +0200 (CEST)


Joseph Barillari writes:
 > (1) How do I access the elements of a tuple in a URL?
 >     accessing /BTreeName/BTreeKey/1(the tuple index)/SomeMethod
 >     doesn't seem to work. When Zope looks up the key in the BTree, it
 >     chokes on the tuple, complaining that it is missing a doc string.
You do not (directly).

You can use a Python Script, say "P", with "traverse_subpath" bound
and use:

	/BTreeName/P/BTreeeKey/1

Inside "P", you would have "traverse_subpath = ['BTreeKey','1']"
and do with it what is adequate...

 > (2) Would it be easier just to add the parent URL to the object
 >     when it's inserted into the BTree?
 >     I.e., from the parent object, call
 > 	  self.data[key] = A()
 > 	  self.data[key].path = self.id*
 >     and when it's necessary to access the parent, 
 >     call self.__of__(restrictedTraverse(self.path))?
It seems that I lack essential context from previous thread
history. At least this looks very strange....

The usual way would look something like:

    class Product(...):
      def __init__(self,...):
        self._btree= BTree(...)

      def accessor(self, key):
        return self._btree[key].__of__(self)

But, as said, I do not know your precise problem....


Dieter