URGENT: need very basic help with Zope2 persistence
Hi, I'm using Zope2 and am trying to get Persistence working for the first time by creating an object store. I'm using the documentation: http://www.zope.org/Documentation/Reference/ObjectPublishingIntro which has a chunk of code to do a very basic store on a Person. I've tried this code both within and without Zope with no success. I'm wondering whether 1. The code (appended) doesn't work for Zope2? When ExternalMethod->Add'ed into Zope, I get: Zope Error Zope has encountered an error while publishing this resource. exceptions.AttributeError Sorry, a Zope error occurred. When run outside Zope, I get: //D/Zope.W32/Extensions:-) python Person.py Traceback (innermost last): File "Person.py", line 14, in ? object_store = BoboPOS.PickleDictionary("people_store.db") File "D:\Zope-2.0.0a4-src\lib\python\BoboPOS\PickleDictionary.py", line 162, i n __init__ jar=PickleJar.PickleJar(db,cache_size,cache_age=cache_age) File "D:\Zope-2.0.0a4-src\lib\python\BoboPOS\PickleJar.py", line 120, in __ini t__ cache=self.cache=PickleCache(cache_size,cache_age) AttributeError: 'int' object has no attribute 'setklassstate' Is there some new code which works in Zope2 to get persistence? 2. My Zope2 installation is somehow broken? I would really appreciate some help on this (I thought) basic issue as it's a show-stopper for what I'm doing. I didn't expect to have this problem since it seem(ed) so well documented and basic. If this question is somehow unanswerable, I'd like to know that too (so I know to give up)! Thanks, = Joe = P.s., I've tried a bunch of variations and searched code for similar fragments all to no avail. If someone has a code fragment or pointer to working code, please let me know. -=- Code -=- import BoboPOS class Person(BoboPOS.Persistent): "A persistent person" def __init__(self,name,age): self.name=name self.age=age def listDB( self): # billy = object_store( "billy") # print billy.name, billy.age return "Hello" # define the object store # object_store = BoboPOS.PickleDictionary("people_store.db") # retrieve billy from the object store # if object_store.has_key("billy"): # if billy is in the object store, then # load it from the object store # billy=object_store["billy"] else: # since billy isn't already in the object # store, we must create the object and # place it in the object store. # billy=object_store["billy"]=Person("Billy",77) # normally Zope will handle transactions, # but in this special case, we need to # commit the transaction to save the new # persistent object # get_transaction().commit() # display the object that we retrieved # from the object store # listDB()
Joe, I'm not 100% certain, but I think things *have* changed in Zope2. There's some messages from Jim and Ty in Zope-Dev digest Vol 1 #92 about BoboPos and Persistence and Zope2. Ominously, they're titled "Dont import from BoboPOS" Sorry I can't be definite on this. Tone
Hi,
I'm using Zope2 and am trying to get Persistence working for the first time by creating an object store. I'm using the documentation:
http://www.zope.org/Documentation/Reference/ObjectPublishingIntro
which has a chunk of code to do a very basic store on a Person. I've tried this code both within and without Zope with no success. I'm wondering whether
1. The code (appended) doesn't work for Zope2? When ExternalMethod->Add'ed into Zope, I get:
Zope Error
Zope has encountered an error while publishing this resource.
exceptions.AttributeError
Sorry, a Zope error occurred.
Tone, thanks for the pointer. As it turns out, my problem was much more basic. To recap, I was following the document: http://www.zope.org/Documentation/Reference/ObjectPublishingIntro This document covers wonderful stuff (DTML, Persistence, etc.) with perfectly bare bones examples. Unfortunately, the Persistence section fails to mention that certain code needs to be installed in the Shared directory (which I'd never heard of as I'm learning Zope) in order to work. I spent ThFr sleuthing this. Yesterday, I began to suspect the docs when I installed Zope 1.10.3 just to get the example to run and it still didn't run. Creepers. So then I went in search of other docs and found: http://www.zope.org/Documentation/Reference/ExternalMethods which specifically mentions, "Zope provides a convenient solution for packaging classes which you wish to use in External Methods. This solution is the 'Shared' package, located in 'lib/python/Shared'." Once I figured that out, I was able to duplicate the example using Zope2 and a few different headers (i.e., not hard and kind of anti-climactic after knocking my head against the wall for two days). I would suggest adding the 'lib/python/Shared' explanation to the ObjectPublishingIntro. I also think it would be very worthwhile having several Samples directories in the appropriate places with working examples of the basic Zope functionality. The examples from the ObjectPublishingIntro would be great for these directories. This way, when a newbie does a text search for some Zope keyword of special interest (e.g., Persistence), they can automatically find useful, simple, working, up-to-date examples. I now have persistence and am ready to keep building my first Zope project. Cheers, = Joe = Tony.McDonald@newcastle.ac.uk wrote:
Joe, I'm not 100% certain, but I think things *have* changed in Zope2. There's some messages from Jim and Ty in Zope-Dev digest Vol 1 #92 about BoboPos and Persistence and Zope2. Ominously, they're titled "Dont import from BoboPOS"
Sorry I can't be definite on this. Tone
Hi,
I'm using Zope2 and am trying to get Persistence working for the first time by creating an object store. I'm using the documentation:
http://www.zope.org/Documentation/Reference/ObjectPublishingIntro
which has a chunk of code to do a very basic store on a Person. I've tried this code both within and without Zope with no success. I'm wondering whether
1. The code (appended) doesn't work for Zope2? When ExternalMethod->Add'ed into Zope, I get:
Zope Error
Zope has encountered an error while publishing this resource.
exceptions.AttributeError
Sorry, a Zope error occurred.
participants (3)
-
Joe Grace -
Joe Grace -
Tony.McDonald@newcastle.ac.uk