[Zope] Save references in a list as object attribut

Thierry Florac thierry.florac at onf.fr
Fri Jan 29 06:31:13 EST 2010


Le vendredi 29 janvier 2010,
  Vladislav Vorobiev <vavvav at mykniga.de> a écrit :
======================================================================
> I try to save references to objects as attribute in a list.
> 
> object.refList=getattr([self.
> context.pfad, 'object'],
> [self.context.pfad, 'object1'])
> 
> After adding and transaction commit I can get my linked objects with
> all attributes and methods
> 
> myObject.refList
> [<myType at object>]
> 
> myObject.refList[0].objectValues()[0].getPhysicalPath()
> ('', 'path', 'object')
> 
> myObject.refList[0].objectValues()[0].absolute_url()
> http://localhost/pfad/object
> 
> I restart the instance and get some other results
> 
> myObject.refList
> [<myType at object>]
> 
> myObject.refList[0].objectValues()[0].getPhysicalPath()
> ('object',)
> 
> myObject.refList[0].objectValues()[0].absolute_url()
> 'object'
> 
> It seems that the in list referenced object ist no more in context
> after restart.
> 
> the constructor for this looks like:
> 
> object  = myObject()
> id=myObject
> myObject.id   = id
> myObject.title= id
> myObject.refList=getattr([self.context.pfad, 'object'],
> [self.context.pfad, 'object1'])
> self.context._setObject(id, ob)
======================================================================

Modifying an object's list attribute "in place" doesn't mark the
persistent object as modified ; so as soon as the object is removed from
the cache, it's modifications are lost.

You should probably :
 - use persistent lists (persistent.list.PersistentList) instead of
   "basic" lists
 - mark object as modified manually (myObject._p_changed = True)
 - or change value of object list attribute :
       myList = myObject.refList
       myList[0] = ...
       myObject.refList = myList

Hope this helps,
Thierry
-- 
Chef de projets intranet/internet
Office National des Forêts - Département Informatique
2, Avenue de Saint-Mandé
75570 Paris Cedex 12
Tél. : 01 40 19 59 64
Fax. : 01 40 19 58 85
Mél. : thierry.florac at onf.fr
Web. : http://www.onf.fr



More information about the Zope mailing list