[Zope] ZPublisher and creating children

Cees de Groot cg@acriter.com
Wed, 03 Mar 1999 15:09:59 +0100


Paul Everitt wrote:

> Cees wrote:
> > The Container, IMHO, "knows" too much about the Child in this
> > case, and
> > it's hard to modify the attribute set of the Child class. Am I doing
> > something wrong? Is there a design pattern here I'm not aware of?
>
> Actually this example shows the beauty of Zope/Bobo programming -- the
> code looks completely like normal Python code, no CGI hackery involved.
>
> Anyway, this is really a Python question, IMO.  You don't the arguments
> to the Child's constructor to be hardwired in the Parent, right?

Well, the underlying issue is the stateless-ness of the whole thing. In
normal python, you'd create an empty child, call the child's editing form
so the user can enter initial data, and only after the user's commit add
the child to the container:

def addChild(self):
     newChild = Child()
     if newChild.editForm() == true:
        container.append(newChild)

in short. I've attempted this in the ZPublisher environment, but to no
avail - either it didn't work at all or it got very messy (with the Child
needing to know about the Parent, etcetera).

I must say, I was under a bit of time pressure last night when looking for
alternatives (wanted to have a beta release on my website before
breakfast), I haven't got around playing with hidden form variables
etcetera yet - that could work. Just hoped somebody on the list here would
have a canned answer - I'm a lazy guy ;-)