[Zope3-Users] z3c.form and subforms in an AddForm?
Marius Gedminas
mgedmin at b4net.lt
Sat Jun 16 12:02:34 EDT 2007
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.
> Here is what I have, using formdemo examples as the basis. Any help on
> getting this to work is greatly appreciated.
>
> IRestaurant with address attribute using schema.Object holding an IAddress.
>
> browser/restaurant.py
>
> class RestaurantAddForm(AddFormLayoutSupport, form.AddForm):
> """Add form"""
>
> template = None
> layout = None
> contentName = None
> label = u'Add Restaurant'
>
> fields = field.Fields(IRestaurant).omit('address')
>
> def update(self):
> self.address = AddressAddForm(self.context.address, self.request) ##
> <---- Problem area
You did not say what the problem was.
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.
> self.address.update()
> super(RestaurantAddForm, self).update()
>
> def create(self, data):
> r = Restaurant()
> r.name = data['name']
> r.description = data['description']
> r.address = data['address']
> return r
>
> def add(self, object):
> self._name = object.name
> self.context[self._name] = object
> return object
>
> def nextURL(self):
> return absoluteURL(self.context[self._name], self.request)
>
>
> browser/address.py
>
> class AddressAddForm(AddFormLayoutSupport, form.AddForm):
> template = None
> layout = None
> contentName = None
> label = u'Address'
>
> fields = field.Fields(IAddress)
> prefix = u'address'
>
> browser/configure.zcml
>
> <!-- Restaurant Add Form -->
> <z3c:pagelet
> name="addRestaurant.html"
> for="zope.app.folder.interfaces.IFolder"
> class=".restaurant.RestaurantAddForm"
> layer="metrod.app.layer.IMetroDBrowserLayer"
> permission="zope.Public" />
>
> <z3c:template
> template="restaurant.pt"
> for=".restaurant.RestaurantAddForm"
> layer="metrod.app.layer.IMetroDBrowserLayer" />
>
> <!-- Address Add Form -->
> <z3c:pagelet
> name="addAddress.html"
> for="metrod.restaurant.interfaces.IAddress"
> class=".address.AddressAddForm"
> layer="metrod.app.layer.IMetroDBrowserLayer"
> permission="zope.Public" />
>
> <z3c:template
> template="address.pt"
> for=".address.AddressAddForm"
> layer="metrod.app.layer.IMetroDBrowserLayer" />
Marius Gedminas
--
Despite all appearances, your boss is a thinking, feeling, human being.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20070616/5cc142b4/attachment.bin
More information about the Zope3-users
mailing list