Problems modifying a "global" attribute of a portal tool.
Hi, I'm working with zope 2.9.1 in debug mode. I have a tool (especifically who_online) where I have created a new class attribute and some methods to modify an read it. A python script is called with a user's click and uses those methods. My problem is that some times when a user modifies the value of the attribute (a python dicctionary) the action takes no effect or it takes effect only in the current transaction. I'm still newbie in zope. The class attribute is called "members_rooms" and the methods are: def joinedRoom(self, member, room): """ Adds the member to the room's list of members. """ self.members_rooms[member] = room logger.info(" %s joined room %s ", member, room) def leftRoom(self, member, room): """ Removes the member from the room where it's supposed to be joined. """ if self.members_rooms.has_key(member): del self.members_rooms[member] logger.info(" %s left the room %s ", member, room) I get log info messages correctly and if I print the value of members_rooms before and after the statement (del or assignment) printed values are correct, but when I query the value of the attribute from a python script just after the "transaction" has finished, the attribute's value has not changed. May some body help me? What am I doing wrong? WhoOnline is a class (and portal tool) that inherits from SimpleItem, Implicit and PropertyManager. Thank you very much. JoseLuis de la Rosa Triviño Técnico de Desarrollo Software FUNDACIÓN IAVANTE joseluis.rosa@iavantefundacion.com Tel. 951 015 300 Este correo electrónico y, en su caso, cualquier fichero anexo, contiene información confidencial exclusivamente dirigida a su(s) destinatario(s). Toda copia o divulgación deberá ser autorizada por IAVANTE. This e-mail and any attachments are confidential and exclusively directed to its adressee(s). Any copy or distribution will have to be authorized by IAVANTE.
--On 4. Juli 2006 13:40:38 +0200 JoseLuis de la Rosa Triviño <joseluis.rosa@iavantefundacion.com> wrote:
if self.members_rooms.has_key(member):
del self.members_rooms[member]
logger.info(" %s left the room %s ", member, room)
Try members = self.members del members[members] self.members = members The problem is likely related to the problem/feature that the ZODB does not notice properly changes to list or dict attrs (which is a documented behavior). -aj -- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web: www.zopyx.com - Email: info@zopyx.com - Phone +49 - 7071 - 793376 E-Publishing, Python, Zope & Plone development, Consulting
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 JoseLuis de la Rosa Triviño wrote:
I'm working with zope 2.9.1 in debug mode.
I have a tool (especifically who_online) where I have created a new class attribute and some methods to modify an read it. A python script is called with a user's click and uses those methods.
My problem is that some times when a user modifies the value of the attribute (a python dicctionary) the action takes no effect or it takes effect only in the current transaction. I'm still newbie in zope.
The class attribute is called "members_rooms" and the methods are:
def joinedRoom(self, member, room): """ Adds the member to the room's list of members. """ self.members_rooms[member] = room logger.info(" %s joined room %s ", member, room)
def leftRoom(self, member, room): """ Removes the member from the room where it's supposed to be joined. """ if self.members_rooms.has_key(member): del self.members_rooms[member] logger.info(" %s left the room %s ", member, room)
I get log info messages correctly and if I print the value of members_rooms before and after the statement (del or assignment) printed values are correct, but when I query the value of the attribute from a python script just after the "transaction" has finished, the attribute's value has not changed.
May some body help me? What am I doing wrong?
WhoOnline is a class (and portal tool) that inherits from SimpleItem, Implicit and PropertyManager.
Make your 'members_rooms' attribute a PersistentMapping, instead of a dict, e.g.: from persistent.mapping import PersistentMapping class WhoOnline(SimpleItem, Implicit, PropertyManager): members_rooms = PersistentMapping() Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEq8gq+gerLs4ltQ4RAk82AJ9kL/Sef3R9fGUFOploqK6nd4fzOACbBE7F E1ivD6tN8bZgZ+RbAeKvz3M= =QM8j -----END PGP SIGNATURE-----
participants (3)
-
Andreas Jung -
JoseLuis de la Rosa Triviño -
Tres Seaver