Re: [Zope3-Users] store persistent objects
Leticia Larrosa wrote: Hi all To fix the error I must change the __init__ of the BTreeContainer class to the follow: """ class persistent_test(BTreeContainer): implements(Ipersistent_test) def __init__(self): BTreeContainer.__init__(self) self['un_padre'] = Padre('Lety','Campanilla') """ Any idea about store object and list of objects? This way is the right way? I'm not sure if I have understood your problem correctly, but here is what you probably could do: For Root: inherit from Persistent and call __init__ of parent class (btw: using super(CurrentClass, self) is the recommended way to do that) class Root(Persistent): def __init__(self): super(Root, self).__init__() self.rootIndex = RootIndex() For list: use PersistentList instead of list. For Leave and RootIndex: inherit from Persistent as well (and remember to call super(...).__init__ if you define own constructor) Regards, Alek Thanks in advanced Leticia Larrosa -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leticia Larrosa Sent: Tuesday, June 20, 2006 11:03 AM To: zope3-users@zope.org Subject: [Zope3-Users] store persistent objects Hi all Resume: I want to store persistent data in the zope database. I must have an object that store others object inside it, including list of objects, etc. I want that when I create the root object automatically create object inside it. Example of python class: """ class Leave: name = u"" (...) class RootIndex: index_list = [] (...) class Root: name = u"" rootIndex = None leave_list = [] def __init__(self): self.rootIndex = RootIndex() """ ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] store persistent objects
Hi all To fix the error I must change the __init__ of the BTreeContainer class to the follow: """ class persistent_test(BTreeContainer): implements(Ipersistent_test) def __init__(self): BTreeContainer.__init__(self) self['un_padre'] = Padre('Lety','Campanilla') """ Any idea about store object and list of objects? This way is the right way? Thanks in advanced Leticia Larrosa -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leticia Larrosa Sent: Tuesday, June 20, 2006 11:03 AM To: zope3-users@zope.org Subject: [Zope3-Users] store persistent objects Hi all Resume: I want to store persistent data in the zope database. I must have an object that store others object inside it, including list of objects, etc. I want that when I create the root object automatically create object inside it. Example of python class: """ class Leave: name = u"" (...) class RootIndex: index_list = [] (...) class Root: name = u"" rootIndex = None leave_list = [] def __init__(self): self.rootIndex = RootIndex() """ I want store this data, for future access to it throw the user interface. I don't know which way is the best, even I don't have any way to do that yet ;) Any idea will be appreciated. Details: I create the following classes, interfaces and zcml directives and get the error when I create a persistent_test throw the ZMI: """ AttributeError: 'persistent_test' object has no attribute '_SampleContainer__data' """ My container overrides __init__ and set the __data value in my class ? (...) """ class IPadre(Interface): nombre_padre = zope.schema.TextLine( title=u"nombre padre", required=True, ) hijo = zope.schema.Object( schema=IHijo, ) class Padre(Persistent): implements(IPadre) nombre_padre = u"" hijo = Hijo(u"") def __init__(self, a_nombre_padre, a_nombre_hijo): self.nombre_padre = a_nombre_padre self.hijo = Hijo(a_nombre_hijo) class Ipersistent_test(IContainer): def __setitem__(name, object): """ Add an Ipersistent_test object. """ class persistent_test(BTreeContainer): implements(Ipersistent_test) def __init__(self): self['un_padre'] = Padre('Lety','Campanilla') """ In my configure.zcml """ """ Traceback: """ Traceback (innermost last): Module zope.publisher.publish, line 138, in publish result = publication.callObject(request, object) Module zope.app.publication.zopepublication, line 164, in callObject return mapply(ob, request.getPositionalArguments(), request) Module zope.publisher.publish, line 113, in mapply return debug_call(object, args) - __traceback_info__: > Module zope.publisher.publish, line 119, in debug_call return object(*args) Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__ return self.im_func(im_self, *args, **kw) Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__ sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0), Module zope.pagetemplate.pagetemplate, line 117, in pt_render strictinsert=0, sourceAnnotations=sourceAnnotations)() Module zope.tal.talinterpreter, line 239, in __call__ self.interpret(self.program) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 869, in do_useMacro self.interpret(macro) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 502, in do_optTag_tal self.do_optTag(stuff) Module zope.tal.talinterpreter, line 487, in do_optTag return self.no_tag(start, program) Module zope.tal.talinterpreter, line 482, in no_tag self.interpret(program) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 839, in do_defineMacro self.interpret(macro) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 941, in do_defineSlot self.interpret(block) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 931, in do_defineSlot self.interpret(slot) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 839, in do_defi
[Zope3-Users] store persistent objects
Hi all Resume: I want to store persistent data in the zope database. I must have an object that store others object inside it, including list of objects, etc. I want that when I create the root object automatically create object inside it. Example of python class: """ class Leave: name = u"" (...) class RootIndex: index_list = [] (...) class Root: name = u"" rootIndex = None leave_list = [] def __init__(self): self.rootIndex = RootIndex() """ I want store this data, for future access to it throw the user interface. I don't know which way is the best, even I don't have any way to do that yet ;) Any idea will be appreciated. Details: I create the following classes, interfaces and zcml directives and get the error when I create a persistent_test throw the ZMI: """ AttributeError: 'persistent_test' object has no attribute '_SampleContainer__data' """ My container overrides __init__ and set the __data value in my class ? (...) """ class IPadre(Interface): nombre_padre = zope.schema.TextLine( title=u"nombre padre", required=True, ) hijo = zope.schema.Object( schema=IHijo, ) class Padre(Persistent): implements(IPadre) nombre_padre = u"" hijo = Hijo(u"") def __init__(self, a_nombre_padre, a_nombre_hijo): self.nombre_padre = a_nombre_padre self.hijo = Hijo(a_nombre_hijo) class Ipersistent_test(IContainer): def __setitem__(name, object): """ Add an Ipersistent_test object. """ class persistent_test(BTreeContainer): implements(Ipersistent_test) def __init__(self): self['un_padre'] = Padre('Lety','Campanilla') """ In my configure.zcml """ """ Traceback: """ Traceback (innermost last): Module zope.publisher.publish, line 138, in publish result = publication.callObject(request, object) Module zope.app.publication.zopepublication, line 164, in callObject return mapply(ob, request.getPositionalArguments(), request) Module zope.publisher.publish, line 113, in mapply return debug_call(object, args) - __traceback_info__: > Module zope.publisher.publish, line 119, in debug_call return object(*args) Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__ return self.im_func(im_self, *args, **kw) Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__ sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0), Module zope.pagetemplate.pagetemplate, line 117, in pt_render strictinsert=0, sourceAnnotations=sourceAnnotations)() Module zope.tal.talinterpreter, line 239, in __call__ self.interpret(self.program) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 869, in do_useMacro self.interpret(macro) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 502, in do_optTag_tal self.do_optTag(stuff) Module zope.tal.talinterpreter, line 487, in do_optTag return self.no_tag(start, program) Module zope.tal.talinterpreter, line 482, in no_tag self.interpret(program) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 839, in do_defineMacro self.interpret(macro) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 941, in do_defineSlot self.interpret(block) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 931, in do_defineSlot self.interpret(slot) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 839, in do_defineMacro self.interpret(macro) Module zope.tal.talinterpreter, line 314, in interpret handlers[opcode](self, args) Module zope.tal.talinterpreter, line 552, in do_setLocal_tal self.engine.setLocal(name, self.engine.evaluateValue(expr)) Module zope.tales.tales, line 698, in evaluate return expression(self) - C:\Python24\Lib\site-packages\zope\app\container\browser\contents.pt - Line 7, Column 4 - Expression: - Names: {'args': (), 'context': , 'default': , 'loop': {}, 'nothing': None, 'options': {}, 'repeat': {}, 'request': http://localhost:8080/@@contents.html>, 'template': , 'usage': , 'view': , 'views': } Module zope.tales.expressions, line 204, in __call__ return self._eval(econtext) Module zope.tales.expressions, line 198, in _eval return ob() Module zope.app.container.browser.contents, line 82, in listContentInfo self.addObject()