Product construction question
----- Forwarded message from zope-dev-request@zope.org ----- Date: Thu, 19 Sep 2002 10:56:07 -0400 Subject: Mailman results for Zope-Dev From: zope-dev-request@zope.org To: joost@lawick.nl Hi, I have some problems with creating folders and objects. PF is a Folderish class. This is the add function (or manage_add): def addPF(self, id=None, title=None, usercontract=None): """ Create a portfolio """ if not id: id = uuidgen() p = PF(id, title, usercontract) self.Destination()._setObject(id, p) # create an account p.addAccount(id='account', valuta='EUR') p.manage_addFolder(id='KKK') return id Now I have the same type of construction for an Account class which is a SimpleItemish class : def addAccount(self, id=None, title=None, valuta=None): """ Create an user Account """ if not id: id = uuidgen() p = Account(id, title, valuta) 1: #self.Destination()._setObject(id, p) 2: self._setObject(id, p) return id When I comment in line 1 and leave out line 2, I get an Attribute Error on Destination. When line 1 is commented out and 2 goes in: Voila! I can still create Account objects in the ZMI. So what does the Destination() method do in construction of an object? Cheers, Joost -- Joost van Lawick E: joost@lawick.com W: http://www.lawick.com/ -- Joost van Lawick E: joost@lawick.com W: http://www.lawick.com/
Joost van Lawick writes:
... def addAccount(self, id=None, title=None, valuta=None): """ Create an user Account """
if not id: id = uuidgen() p = Account(id, title, valuta) 1: #self.Destination()._setObject(id, p) 2: self._setObject(id, p) return id
When I comment in line 1 and leave out line 2, I get an Attribute Error on Destination. When line 1 is commented out and 2 goes in: Voila! I can still create Account objects in the ZMI.
So what does the Destination() method do in construction of an object? "Destination" is a method of "FactoryDispatcher"s, the kind of thing returned by
"manage_addProduct[product_name]" Apparently, you call "addAccount" with a "self" that is not a "FactoryDispatcher". Dieter
def addPF(self, id=None, title=None, usercontract=None): """ Create a portfolio """
if not id: id = uuidgen() p = PF(id, title, usercontract) self.Destination()._setObject(id, p) # create an account p.addAccount(id='account', valuta='EUR') p.manage_addFolder(id='KKK') return id
Do not call the first argument "self" if it is not a real method self. Here it should probably be called "dispatcher"
def addAccount(self, id=None, title=None, valuta=None): """ Create an user Account """
if not id: id = uuidgen() p = Account(id, title, valuta) 1: #self.Destination()._setObject(id, p) 2: self._setObject(id, p) return id
Same comment. Have you read the Developer's Guide? It talks about product creation and should answer your questions. Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (3)
-
Dieter Maurer -
Florent Guillaume -
Joost van Lawick