[Zope] Getting a handle on the results of constructors
Andreas Heckel
andreas@easyleading.org
Thu, 18 Apr 2002 13:01:31 +0200
Dennis Allison wrote:
>
> In an External Method (that is, unrestricted python), for example, when
> you create a Folder one writes:
>
> self.manage_addProduct['OFSP'].manage_addFolder( id,title="folder")
>
> one would think that it would return the object it just constructed so it
> would be easy to use the new product to, say, create another folder or a
> file inside. But that appears not to be the case. (In my example, the
> folder was successfully created but the code
>
> handle = self.manage_addProduct...
>
> returned None. That made what I thought was the obvious way to handle
> things, namely applying the constructor to the new folder using
>
> handle = self.manage_addProduct...
Here is a short example on how to create a new Folder containing a
DTMLMethod
Assumed there is a my_html.dtml file in your product directory :
import OFS.Folder
from OFS.DTMLMethod import DTMLMethod
from Globals import HTMLFile
dtml_template=HTMLFile('my_html',globals())
dtml_obj=DTMLMethod()
dtml_obj.id='my_html'
index_obj.manage_edit(data=dtml_template,title='Welcome Home')
folder_obj=OFS.Folder.Folder()
folder_obj.id='NewFolder'
folder_obj._setObject('my_html',index_obj)
self._setObject('NewFolder',folder_obj)
--
_______________________________________________________________________
Andreas Heckel andreas@easyleading.org