[Zope3-Users] AW: AW: z3c.form and subforms in an AddForm?
Mats Nordgren
mats at ronin-group.org
Tue Jun 19 13:39:43 EDT 2007
Roger,
> You missed in the AddressAddForm ``self.widgets.ignoreContext = True``
I see that I missed that statement, it was late on a sleepless night, but I
couldn't get this out of my head. In any case, I've changed my code to
match the example you gave in the repository. I also have the templates
defined in the view instead of through zcml as you have in the tests.
browser/restaurant.py
class RestaurantAddForm(form.EditForm):
"""Add form"""
fields = field.Fields(IRestaurant).select('name', 'description')
template = viewpagetemplatefile.ViewPageTemplateFile('restaurant.pt')
prefix = u'restaurant'
def updateWidgets(self):
self.widgets = component.getMultiAdapter((
self, self.request, self.getContent()), IWidgets)
self.widgets.ignoreContext = True
self.widgets.update()
def update(self):
self.address = AddressAddForm(None, self.request)
self.address.update()
super(RestaurantAddForm, self).update()
browser/address.py
class AddressAddForm(form.EditForm):
fields = field.Fields(IAddress)
template = viewpagetemplatefile.ViewPageTemplateFile('address.pt')
prefix = u'address'
def updateWidgets(self):
self.widgets = component.getMultiAdapter((
self, self.request, self.getContent()), IWidgets)
self.widgets.ingoreContext = True
self.widgets.update()
browser/configure.zcml
<z3c:pagelet
name="addRestaurant.html"
for="zope.app.container.interfaces.IContainer"
class=".restaurant.RestaurantAddForm"
layer="metrod.app.layer.IMetroDBrowserLayer"
permission="zope.Public" />
I believe those matches your example exactly but I still get the adaption
error when the form should be displayed.
Traceback (most recent call last):
Module zope.publisher.publish, line 133, in publish
result = publication.callObject(request, obj)
Module zope.app.publication.zopepublication, line 161, in callObject
return mapply(ob, request.getPositionalArguments(), request)
Module zope.publisher.publish, line 108, in mapply
return debug_call(obj, args)
- __traceback_info__: <security proxied
z3c.pagelet.zcml.RestaurantAddForm instance at 0x02EE17D0>
Module zope.publisher.publish, line 114, in debug_call
return obj(*args)
Module z3c.form.form, line 139, in __call__
self.update()
Module metrod.restaurant.browser.restaurant, line 31, in update
self.address.update()
Module z3c.form.form, line 134, in update
super(Form, self).update()
Module z3c.form.form, line 83, in update
self.updateWidgets()
Module metrod.restaurant.browser.address, line 21, in updateWidgets
self.widgets.update()
Module z3c.form.field, line 245, in update
widget.update()
Module z3c.form.widget, line 96, in update
value = zope.component.getMultiAdapter(
Module z3c.form.datamanager, line 48, in get
context = self.field.interface(context)
TypeError: ('Could not adapt', None, <InterfaceClass
metrod.restaurant.interfaces.IAddress>)
Am I forgetting some configuration on my forms? I have not configured
anything for AddressAddForm could that be the issue?
> And take more care about the super classes. you are suing a EditForm
> as base. Same in the RestaurantAddForm.
Not sure I'm understanding this, your example used EditForm without any
thought on superclasses.
Again thanks for all your time and effort, I really appreciate this.
Mats Nordgren
PS. Would there be a chance you could include the car/owner example in the
z3c.formdemo package?
More information about the Zope3-users
mailing list