[Zope] Help with Zope2 persistence?

Joe Grace occam@serv.net
Fri, 23 Jul 1999 08:23:17 -0700


I should add that the problems I'm having are all compile time (import
time?) and "AttributeError: get_key" type errors, so I'm missing something
basic.

Thanks,

= Joe =


Joe Grace wrote:

> Hi,
>
> I'm wondering if it's possible to use Zope persistence outside of Zope
> for testing.  I copied the code from the Persistence section of
>
>     http://www.zope.org/Documentation/Reference/ObjectPublishingIntro
>
> I also tried a variety of variations on BoboPOS.Persistent according to
> a comment recently made by Michel:
>
>     Actually, Persistence.Persistent.  BoboPOS will work but it's not
> 'the
>     way'.  It's legacy.
>
> So, I've gotten it to "from Persistence import Persistent" and to
> inherit, but I don't know what the correct invocation is to create the
> database.  BoboPOS.PickleDictionary(), and Persistent.PickleDictionary()
> don't work.  I've been perusing code for an example of something which
> seems to create a DB from scratch, but the only one I found
>
> I know this is a newbie question, but if someone has a complete sample
> code analogous to the following, I'd be very thankful for the insight.
> Ideally, it would work outside Zope (getting all the imports correct, if
> possible), but just working within Zope would be nice too.
>
> The "has_key" method seems to be a missing link too.  That method
> doesn't seem to exist in the objects I was guessing were my DB objects.
> I'd like to know how to do that test using Zope2 code.
>
> (I hope this question makes sense.)  Just looking for the basics.
>
> Thanks,
>
> = Joe =
>
> -=-  Basic code fragment from docs follows:  -=-
>
>        #  I'm assuming this changes to "import Persistent from
> Persistence" or somesuch?
>        import BoboPOS
>
>        #  I'm assuming this changes to "class Person( Persistent):".
>        class Person(BoboPOS.Persistent):
>                "A persistent person"
>                def __init__(self,name,age):
>                        self.name=name
>                        self.age=age
>
>        # ???  What goes here?
>       object_store=BoboPOS.PickleDictionary("people_store.db")
>
>        # ???  Does object_store still use has_key to check for
> existence, or is there another method?
>       if object_store.has_key("billy"):
>                billy=object_store["billy"]
>        else:
>                billy=object_store["billy"]=Person("Billy",77)
>                get_transaction().commit()
>
>        print billy.name, billy.age
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (To receive general Zope announcements, see:
> http://www.zope.org/mailman/listinfo/zope-announce
>
> For developer-specific issues, zope-dev@zope.org -
> http://www.zope.org/mailman/listinfo/zope-dev )