[Zope] Re: [Zope-dev] creating one ZClass instance in the constructor of another

Kevin Dangoor kid@kendermedia.com
Thu, 22 Jul 1999 22:17:55 -0400 (EDT)


Hi,

In some recent messages, there were people talking
about creating objects from within External Methods.
In there, after the createInObjectManager call, they
call a _setObject method (or something like that).
Unfortunately, we can't do that from DTML because it
starts with _.

Maybe there is some piece missing that is need to
create these objects wherever you wish via DTML?

Not to confuse the issue, but I've got a slightly
different situation and a slightly different problem
(but no luck, either :)

I have two ZClasses: KMArticleStore and KMArticle.
There is a method within KMArticleStore that I would
like to use to create new KMArticles.

I've tried a few variations to get this to work. Brian
(Lloyd)'s suggestion
<dtml-call
"Control_Panel.Products.Kendermedia.KMArticle_add(REQUEST)">

Yields a NameError (KMArticle), here:
Object: KMArticle.createInObjectManager(REQUEST['id'],
REQUEST)

I did, at one point, manage to get the article added
to the Products part of the control panel :)
(I think by calling
Control_Panel.Products.Kendermedia.KMArticle.createInObjectManager
directly)

Kevin


--- Brian Hooper <brian@garage.co.jp> wrote:
> Hi, thanks for the response!
> 
> Brian Lloyd <Brian@digicool.com> wrote:
> 
> > > Hi Zopistas -
> > > 
> > > This is probably a really easy one, but I was
> wondering if 
> > > anyone knows
> > > how to create an instance of one ZClass inside
> the constructor of a
> > > different ZClass.  To illustrate with an
> example:
> > > 
> > > I have defined two ZClasses, a ProjectManager
> and a GuestBook (I
> > > reimplemented the old Guestbook example product
> using ZClasses) as
> > > separate Products (since they are not really
> intrinsically related).
> > > I want to use the GuestBook in the
> ProjectManager, but I can't figure
> > > out how to create the GuestBook in the
> ProjectManager's constructor.
> > > 
> > > I want to do something like
> > > 
> > > <!--#call "GuestBook_add(id)"-->
> > > 
> > > in the ProjectManager_add method; however, since
> the other Product's
> > > names don't seem to be defined in the namespace
> of ProjectManager_add,
> > > this doesn't work.
> > > 
> > > Can anyone please tell me the magical solution
> to this problem?
> > > 
> > > 
> > > --Brian Hooper
> > 
> > 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)"-->
> 
> Puzzlingly (at first), there was no error, but also
> the 'messages'
> GuestBook did not appear in my newly created
> ProjectManager instance. 
> Apparently, the GuestBook instance is being created
> but instead of being
> contained in the ProjectManager instance, it is
> simply returned inside
> the ProjectManager_add constructor page.  When I
> remove the redirect at
> the end of the ProjectManager constructor and
> <!--#var--> instead of
> <!--#call--> the above DTML statements, I get a
> 
> <GuestBook instance at 80f12e0>
> 
> in the ProjectManager_add page.
> 
> I guess this has something to do with how
> createInObjectManager works;
> however, I'm still not able to get my noodle around
> what's going on
> there (turns my brain to spaghetti).  Is there any
> way of skirting around
> this problem?  (not the brain spaghetti problem, the
> instance in an
> instance problem)
> 
> --Brian
> 

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com