On Saturday 16 June 2007 12:02, Marius Gedminas wrote:
> On Fri, Jun 15, 2007 at 10:52:24AM -0700, gnosis wrote:
> > I've been trying out the new z3c form package and like what I see. I am
> > having problems getting a subform in an AddForm though. The subform.txt
> > covers EditForms where you have a context object to work on, in an
> > AddForm the context is the underlying IContainer.
> Really? Usually in Zope 3 (zope.app.form or zope.formlib) the context
> of an add form is the IAdding view. To get the container you have to
> use self.context.context.
z3c.form does not support the lame IAdding pattern by default. That said, I
feel inclined to add an "AddingAddForm" to the compatibility module but
strongly discourage its use.
> > def update(self):
> > self.address = AddressAddForm(self.context.address, self.request)
> > ## <---- Problem area
> You did not say what the problem was.
The context does not have an attribute called "address".
> I suspect that you ought to have a simple subform here (nor an add form,
> since you're not going to add the address object into a container --
> you're going to set it on an attribute; also not an edit form since the
> address object doesn't exist yet).
> I'm not familiar with z3c.form, but I'm betting that it follows the same
> conventions as the older Zope 3 form modules.
Right, you could use a sub-form just fine, since you do not need all the
actions. But you will need to customize the widget creation to ignore the
> > self.address.update()
> > super(RestaurantAddForm, self).update()
This reminds me; this needs to be the other way around, because you need to
first create the parent object.
> > def create(self, data):
> > r = Restaurant()
> > r.name = data['name']
> > r.description = data['description']
> > r.address = data['address']
Mmh, this will not work either, because the data will not contain the address
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
Zope3-users mailing list