[Zope3-Users] OOBTree instances lose attributes upon restart
Hi everyone. I've been fighting with this for a while now. So I mail the list for a suggestion. I have a `Variable` class wich I subclass from OOBTree, because I need a dictionary with the min, max options that OOBTree methods give. My object is supposed to store datetime.datetime instances as keys and floats numbers as values. eg: temperature[datetime(2007, 4, 6, 12, 8)] = 25.8 I didn't use BTreeContainer because only takes strings as keys, and I don't want to map datetime to strings and back. Here's my class definition: class Variable(OOBTree, Contained): implements(IVariable, IAttributeAnnotatable) name = None units = None I start the server and everything works like a charm. My AddForm works OK for the Variable class. I checked its create() method (with assert statements) and the returned instances contain the name and units attributes set from the form. But if I stop the server and restart later, my data (datetimes and floats) are still there, but my name and units attributes are None!! I tried to subclass from (OOBTree, Persistent, Contained) too, and it didn't work either. If I subclass only from (PersistentDict) everything works. Data and attributes are mantained upon restart, but I lose the min, max functionality I like :( What could be the problem or a possible solution to this issue? Thanks. Looking for earth-friendly autos? Browse Top Cars by Green Rating at Yahoo! Autos' Green Center. http://autos.yahoo.com/green_center/ ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] OOBTree instances lose attributes upon restart
Douglas Douglas wrote: Hi everyone. I've been fighting with this for a while now. So I mail the list for a suggestion. I have a `Variable` class wich I subclass from OOBTree, because I need a dictionary with the min, max options that OOBTree methods give. My object is supposed to store datetime.datetime instances as keys and floats numbers as values. eg: temperature[datetime(2007, 4, 6, 12, 8)] = 25.8 I didn't use BTreeContainer because only takes strings as keys, and I don't want to map datetime to strings and back. Here's my class definition: class Variable(OOBTree, Contained): implements(IVariable, IAttributeAnnotatable) name = None units = None class Variable(Persistent, Contained): def __init__(self): self.__mydata = OOBTree() def keys(self, min, max ): return self.__mydata.keys(min, max, ) For example see implementations in zope/app/container/sample.py ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] OOBTree instances lose attributes upon restart
On Fri, Apr 06, 2007 at 12:53:06AM -0700, Douglas Douglas wrote: Here's my class definition: class Variable(OOBTree, Contained): implements(IVariable, IAttributeAnnotatable) name = None units = None I start the server and everything works like a charm. My AddForm works OK for the Variable class. I checked its create() method (with assert statements) and the returned instances contain the name and units attributes set from the form. But if I stop the server and restart later, my data (datetimes and floats) are still there, but my name and units attributes are None!! OOBTree is at fault here. I'm sure that if you investigated it, you'd find a custom __getstate__. I suggest that you do not subclass OOBTree but instead contain it in an attribute and delegate all the methods. class Variable(Persistent, Contained): implements(...) def __init__(self): self.data = OOBTree() def __getitem__(self, key): return self.data[key] ... Marius Gedminas -- I dont know about madness (and anyway, the little green martians dancing around me tell me not to worry...), but I've implemented something not unlike this just now. -- Peter Sabaini signature.asc Description: Digital signature ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users