[Zope] persistence

Michel Pelletier michel@digicool.com
Tue, 6 Jul 1999 07:41:24 -0400


> -----Original Message-----
> From: jiri stepan [mailto:zope@etnetera.cz]
> Sent: Tuesday, July 06, 1999 7:10 AM
> To: zope conference
> Subject: [Zope] persistence
> 
> 
> Hello
> I'm trying to work with persistent objects in a PickleDictionary. The
> objects are not writen into database file - they exists only in memory
> and they are not persistent. I don't know how to commit new changes.
> 
> Python code:
> 
> ...
> 
> db=BoboPOS.PickleDictionary(db_loc+"databaze2")
> if db.has_key('customers_db'):
> 	customers=db['customers_db']
> else:
> 	customers=db['customers_db']=Customers() 
> 	customers.addCustomer('hu','sdf','dsf','sdf','df') 
> #this is test 
> 							   # -works-
> 	get_transaction().commit()
> 
> #ok - this works customer, which is added here is persistent
> 
> ..but later ..
> 
> class AdressBook(
>     OFS.SimpleItem.Item,
>     Persistent,
>     Acquisition.Implicit,
>     AccessControl.Role.RoleManager,
>     ):
>     ....
>     def manage_addZakaznik(self,id,firstname,surname,tel,note,
> REQUEST=None):
> 	""" adds a new customer into persistent storage 
> 	    and writes the message
> 	"""
> 	
> 	if REQUEST is not None:      	
>     	    
> 	    customers.addZakaznik(id,firstname,surname,tel,note)
> 	    get_transaction().commit()
> 
> 	    return MessageDialog(
> 		title='Added',
> 		message='zakaznik byl pridan.' ,
> 		action ='./manage_main',
> 		)
> #this customer is added into the object 'customers' and I can 
> work with
> it, but it isn't persistent - after Zope's restart is lost.
> 

I think your looking for:

	self.customers.addZakaznik....

or something like that.  Your object is not  being saved persistently
because you are not assigning to self.customers (the customers attribute
of the self object, which is an instance of AddressBook) but you are
rather assigning to a localy defined object customers.

Since your code is not complete enough to tell what you want 'customers'
to be, this is my best guess.  In any case, I suspect your problem has
to do with improper use of Python scope.

-Michel

> ------------
> 
> Thank's for any informations
> 
> 
> Jiri Stepan
> (zope@etnetera.cz)
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
> 
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
>