[Zope-CMF] Persistent dictionaries
Thomas Olsen
tol@tanghus.dk
Fri, 24 Aug 2001 02:54:45 +0200
Hi
I'm working on a CMF Product which is based on PortalFolder and
PortalContent. This Folderish object contains some items which inherits from
OFS.SimpleItem.Item, Persistence.Persistent and Aquisition.Implicit.
These items have (had) some properties which are speciel to their class. In
order to get around the problem with adding new attributes and having
instantiated objects which doesn't have the attributes I decided to keep the
attributes in a dictionary. So in my base class I did:
---snip--------------------------------------------
class AbstractElement(Persistent, Item, Implicit):
""" Abstract base class for Element objects. """
_attributes = PersistentMapping()
def __getattr__(self, name):
if self._attributes.has_key(name):
return self._attributes[name]
else:
raise AttributeError, name
---snip--------------------------------------------
and my derived classes look something like this:
---snip--------------------------------------------
class TextElement(AbstractElement):
"""
text element.
"""
meta_type = 'Text Element'
def __init__(self, id):
self.id = id
self._attributes = {'value':'','html':'','alignment':''}
def edit(self, value, html, alignment):
""" Update the properties """
self._attributes['alignment'] = str(alignment)
self._attributes['value'] = str(value)
self._attributes['html'] = utils._format_stx(self.value)
---snip--------------------------------------------
It works great - until the object gets unloaded from the memory :-(
What am I doing wrong?
--
Regards,
Thomas Olsen
http://www.tanghus.dk