[Zope3-Users] formlib, action decorators and inheritance

Lorenzo Gil Sanchez lgs at sicem.biz
Mon Jul 17 04:27:26 EDT 2006


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):

     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