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 """ <interface interface="persistent_test.Ipersistent_test" type="zope.app.content.interfaces.IContentType" /> <content class="persistent_test.persistent_test"> <implements interface="zope.app.annotation.interfaces.IAttributeAnnotatable" /> <implements interface="zope.app.container.interfaces.IContentContainer" /> <factory id="persistent_test.persistent_test" description="persistent test"/> <require permission="zope.ManageContent" interface="persistent_test.Ipersistent_test" /> </content> <interface interface="persistent_test.IPadre" type="zope.app.content.interfaces.IContentType" /> <content class="persistent_test.Padre"> <implements interface="zope.app.annotation.interfaces.IAttributeAnnotatable" /> <implements interface="zope.app.container.interfaces.IContentContainer" /> <factory id="persistent_test.Padre" description="Padre"/> <require permission="zope.ManageContent" interface="persistent_test.IPadre" /> <require permission="zope.ManageContent" set_schema="persistent_test.IPadre" /> </content> <browser:addMenuItem class="persistent_test.persistent_test" title="Persistent Test" permission="zope.ManageContent" /> """ 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__: <BoundPageTemplateFile of <zope.app.publisher.browser.viewmeta.Contents object at 0x02847850>> 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: <PathExpr standard:'view/listContentInfo'> - Names: {'args': (), 'context': <zope.app.folder.folder.Folder object at 0x01986EF0>, 'default': <object object at 0x00A8C500>, 'loop': {}, 'nothing': None, 'options': {}, 'repeat': {}, 'request': <zope.publisher.browser.BrowserRequest instance URL=http://localhost:8080/@@contents.html>, 'template': <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object at 0x01782910>, 'usage': <zope.pagetemplate.pagetemplate.TemplateUsage object at 0x028475F0>, 'view': <zope.app.publisher.browser.viewmeta.Contents object at 0x02847850>, 'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper object at 0x02847B70>} 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() Module zope.app.container.browser.contents, line 248, in addObject adding.action(request['type_name'], new) Module zope.app.container.browser.adding, line 146, in action content = factory() Module zope.component.factory, line 37, in __call__ return self._callable(*args, **kw) Module persistent_test, line 46, in __init__ self['un_padre'] = Padre('Lety','Campanilla') Module zope.app.container.sample, line 86, in __setitem__ setitem(self, self.__data.__setitem__, key, object) AttributeError: 'persistent_test' object has no attribute '_SampleContainer__data' """ Thanks in advanced. Leticia Larrosa __________________________________________ XIII Convencisn Cientmfica de Ingenierma y Arquitectura 28/noviembre al 1/diciembre de 2006 Cujae, Ciudad de la Habana, Cuba http://www.cujae.edu.cu/eventos/convencion _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users __________________________________________ XIII Convención Científica de Ingeniería y Arquitectura 28/noviembre al 1/diciembre de 2006 Cujae, Ciudad de la Habana, Cuba http://www.cujae.edu.cu/eventos/convencion _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users