AW: [Zope3-Users] z3c.form and subforms in an AddForm?

Roger Ineichen dev at projekt01.ch
Sun Jun 17 13:40:03 EDT 2007


Hi 

> Betreff: [Zope3-Users] z3c.form and subforms in an AddForm?
> 
> 
> 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.
> 
> 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
>         self.address.update()
>         super(RestaurantAddForm, self).update()

You can add a custom setupWidgets method in the sub form which
disables the context adaption.

Stephan and I duscussed this during development, I think we
should add the hook into the form. He thinks not. But I guess
we have to discuss this once again.

Here is the method for context less forms:

def updateWidgets(self):
    self.widgets = zope.component.getMultiAdapter(
        (self, self.request, self.getContent()), interfaces.IWidgets)
    self.widgets.ignoreContext = True
    self.widgets.ignoreReadonly = True
    self.widgets.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)


Regards
Roger Ineichen
_____________________________
END OF MESSAGE



More information about the Zope3-users mailing list