[Zope3-Users] Re: formlib, action decorators and inheritance

Jürgen Kartnaller juergen at kartnaller.at
Mon Jul 17 05:01:13 EDT 2006


Hi Lorenzo.

Lorenzo Gil Sanchez wrote:
> Hi,
> 
> I have an add form which a subclass of form.AddForm. It just adds a 
> 'cancel' action.
> 
> This is my code:
> 
> class AddView(form.AddForm):
Try this here :
       actions = form.AddForm.actions
> 
>     form_fields = form.Fields(IDocument).omit('__name__')
> 
>     def create(self, data):
>         return Document(**data)
> 
>     def nextURL(self):
>         url = zapi.absoluteURL(self.context.context, self.request)
>         return url
> 
>     @form.action(u'Cancel', validator=always_good)
>     def handle_cancel(self, action, data):
>         self.request.response.redirect(self.nextURL())
> 
> When I define the 'cancel' action using the @form.action decorator it 
> seems that the 'add' action is lost. That action is defined in my super 
> class.
> 
> As a workaround I do the following:
> 
>     def handle_cancel(self, action, data):
>         self.request.response.redirect(self.nextURL())
> 
>     actions = form.AddForm.actions + form.Actions(
>         form.Action(u'Cancel',
>                     success='handle_cancel', validator=always_good),
>         )
> 
> but I'm not sure if I'm missing something since my workaround is uglier 
> than the decorator solution.
> 
> Best regards,
> 
> Lorenzo Gil



More information about the Zope3-users mailing list