[Zope] creating one ZClass instance in the constructor of another

Kevin Dangoor kid@kendermedia.com
Thu, 29 Jul 1999 21:04:43 -0400


Hi,

    Brian Hooper and I have been trying to figure out how to add ZClass
instances via DTML... and I've finally figured out what I've been doing
wrong...

The couple of examples that were tried in the original messages below could
be corrected by doing:
<dtml-call "Control_Panel.Products.Guestbook.Guestbook_add(_.None, _)">

(Note: my code is actually a little different, because I'm working with
different products and classes. YMMV)

For me, the whole trouble was that the namespace wasn't set properly for the
add method to run.
An alternate syntax is:
<dtml-call "manage_addProduct['Guestbook'].Guestbook_add(_.None, _)">

There is a side-effect here from the default add method that I didn't want:
the default method will redirect to the management screen.
So, I ended up just doing:
<dtml-call
"Control_Panel.Products.Guestbook.Guestbook.createInObjectManager(REQUEST['i
d'], REQUEST)">

In fact, in my current situation, I am making a new ZClass subclass instance
(KMYear is a subclass of KMArticleStore). In this scenario, I can just call:
<dtml-call "KMYear.createInObjectManager(newID, REQUEST)">

After all of that, I believe that I will ultimately change my add method to
behave the way I want, because I will be using it in conjunction with a
Findable class. I just wanted to pass along all of the ways that this can
work, for anyone else trying to instantiate ZClasses with DTML.

Kevin

In http://www.zope.org/pipermail/zope/1999-July/007133.html, Brian Hooper
wrote:

Brian Lloyd <Brian@digicool.com> wrote:
> This is a little ugly, but it should work (untested). Let me know!
>
> <!--#call "Control_Panel.Products.Guestbook.Guestbook_add(id)"-->

I tried this (or rather, something like it - sharp observers may have
noticed that I screwed up the question a little; since GuestBook_add is
a DTML Method, it should probably be called <!--#call
"GuestBook_add(REQUEST)"--> after resetting the id in REQUEST to
whatever I want the new object id to be):

       <!--#call "REQUEST.set(id, 'messages')"-->
       <!--#call
"Control_Panel.Products.GuestBook.GuestBook_add(REQUEST)"-->