[Zope] [ZClass constructor question]: How can I copy objects into my container class?

Jim Washington jwashin@vt.edu
Wed, 21 Nov 2001 20:17:26 -0500


Simon Brogden wrote:

>Hi All,
>
>I'm (banging my head against the desk) writing to write a ZClass that
>inherits from ObjectManager and can contain other objects (DTMLMethods &
>Images). When an instance of the class is created I want to copy/create
>a couple of default DTML methods inside the instance, so the user can
>modify them.
>
>Trouble is, the methods appear at the same nesting level as the class is
>created at, not contained within it.
>
>I'm putting the create/copy call inside the class constructor method:
><dtml-call "manage_addProduct['OFSP'].manage_addDTMLMethod(....)>
>
>I've trawled the how-to's & the example products (the "How to: Build a
>searchable job board" is excellent BTW) to no avail.
>
>Does anyone know where I'm going wrong? 
>
Hi, Simon

The standard answer is to use the dtml-with tag:

<dtml-with newitemname>
<dtml-call "manage_addBlah(params)">
</dtml-with>

But you might consider making a python script called "init" or something 
like that for the class you are adding:

methodID = 'example'
methodTitle = 'This is the example method"
methodStandardText = """<standard_html_header>
            example dtml text goes here
            <dtml-var standard_html_footer>"""
container.manage_addDTMLMethod(id=methodID,title="")
container[methodID].manage_edit(data=methodStandardText, title=methodTitle)

then after you add the new item,

<dtml-call "newitemname.init()">

hth,

-- Jim Washington