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

Lorenzo Gil Sanchez lgs at sicem.biz
Mon Jul 17 05:01:33 EDT 2006


Hi Jürgen,

I did what you say and it's a little bit better.

Thanks

Lorenzo

Jürgen Kartnaller wrote:
> 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
> 
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
> 



More information about the Zope3-users mailing list