zope folks, if this has already been covered somewhere, let me know-- i just couldn't find information about it on the Zope site! i'm building a Zope product that needs to store some persistent information in the Zope object database. the information needs to be accessible to all instances of that product. my approach was: write a class that derives from Persistence.Persistent that will store the data and mediate access to it. then, in the product's __init__.py file, instantiate this class and put the instance into the Zope object database, then call get_transaction().commit() to commit it. theoretically, once my instance is in the Zope object database, other objects can access it-- adding or subtracting data. and the instance will handle committing its own changes, so it won't forget anything between restarts of Zope. my question: how do actually do this?? :-) i found a kludgy way to store a class instance in the Zope object database from the product's __init__.py file, but i can't figure out how to connect to this object from a random instance of my product. amy i going about this all wrong? is there a better way of storing and accessing persistent objects from inside of Zope? or if my approach is correct, how do actually implement it? here's what i am doing in the product's __init__.py file: # get the ZODB root-- kludge! root=context._ProductContext__app._p_jar.root() # now make the object instance if we need to if root.has_key('FooObject'): print "FooObject already in DB" else: print "made new FooObject." root['FooObject'] = Foo.Foo() get_transaction().commit() the problem seems to be, i don't know how to get access to the Zope object database's root object from inside an instance of my product. what i want to do inside the product base class, during an add or delete of an instance of the product, is something like: # somehow get the root of the Zope ZODB :-) root=Somehow.get.ZODB.root() root['FooObject'].remove_item(someitem) get_transaction().commit() any help is greatly appreciated! cheers adam -- Adam Feuer adamf@pobox.com
participants (1)
-
Adam Feuer