Re: [Zope] Save references in a list as object attribut

2010-01-29 Thread Thierry Florac
Le vendredi 29 janvier 2010,
  Vladislav Vorobiev vav...@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.flo...@onf.fr
Web. : http://www.onf.fr

___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Save references in a list as object attribut

2010-01-29 Thread Vladislav Vorobiev
Thierry Florac wrote:
 Le vendredi 29 janvier 2010,
   Vladislav Vorobiev vav...@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
   

Thierry thank you  for answer but it doesn't help.

I implement all what you sad. I tried with normal “list” and than 
swiched to “PersistentList”

code looks like that http://www.dict.cc/englisch-deutsch/following.html:


from persistent.list import PersistentList
import transaction

snip

myList=PersistentList([self.context.pfad, 'object])   
myList[0] = PersistentList([self.context.pfad, 'object])[0] #hope I 
anderstud you right

ob.refList= myList 
ob._p_changed = True
ob.refList._p_changed = True 
self.context._setObject(id, ob)

After add I call again:


ob._p_changed = True
ob.refList._p_changed = True 
transaction.commit()

I see the commitet trunsactions in ZMI

The same problem. After restart ist the Attribut not in context.

For example return's

Before restart: ***1
ob.refList[0].objectValues()[0].absolute_url()
/pfad/object/FirstObjectOfReferencedObject

After restart only the id of the object:
ob.refList[0].objectValues()[0].absolute_url()
FirstObjectOfReferencedObject

Here is a place for an other question:

Normaly self.absolute_url() returns url with hostname, 
(http://localhost/bla/bla)
but already http://www.dict.cc/englisch-deutsch/already.html befor 
restart I get without http://localhost/... http://localhost/ see ***1

It seem's that I forgot something.  *I* 
http://www.dict.cc/englisch-deutsch/I.html would 
http://www.dict.cc/englisch-deutsch/would.html be 
http://www.dict.cc/englisch-deutsch/be.html *glad* 
http://www.dict.cc/englisch-deutsch/glad.html to if somebody explain 
me this problem.


Best regards

Vladislav


___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Save references in a list as object attribut

2010-01-29 Thread Vladislav Vorobiev
Thierry Florac wrote:
 Le vendredi 29 janvier 2010,
   Vladislav Vorobiev vav...@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
   
Thierry thank you  for answer but it doesn't help.

I implement all what you sad. I tried with normal “list” and than 
swiched to “PersistentList”

code looks like that:

from persistent.list import PersistentList
import transaction

snip

myList=PersistentList([self.context.pfad, 'object])   
myList[0] = PersistentList([self.context.pfad, 'object])[0]  #hope I 
anderstud you right

ob.refList= myList 
ob._p_changed = True
ob.refList._p_changed = True 
self.context._setObject(id, ob)

After add I call again:

ob._p_changed = True
ob.refList._p_changed = True 
transaction.commit()

I see the commitet trunsactions in ZMI

The same problem. After restart ist the Attribut not in context.

For example return's

Before restart: ***1
ob.refList[0].objectValues()[0].absolute_url()
/pfad/object/FirstObjectOfReferencedObject

After restart only the id of the object:
ob.refList[0].objectValues()[0].absolute_url()
FirstObjectOfReferencedObject

Here is a place for an other question:

Normaly  self.absolute_url() returns url with hostname,  
(http://localhost/bla/bla)
but already befor restart I get without http://localhost/... see ***1

It seem's that I forgot something.  I would be glad to if somebody 
explain me this problem.

Best regards
Vladislav

ps: sorry for unclean preview message :-)
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )