[Zope3-dev] Usage of actions in zope.formlib ... was: Re: Add flexibility to zope.formlib.form.EditFormBase

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Wed May 9 13:44:13 EDT 2007


> So while the behavior may seem a little odd, it let's you construct
> the validation scenarios you need.
Hmm... you're right.
So In fact for normalization and validation and in general preprocessing
we may use'validator' function like that (not tested):

def myactionvalidator(form, action, data):
     # fill data dictionary
     errors = form.validate(action, data)
     if errors:
         return errors

     # data dictionary is filled so it is possible
     # to normalize data or do other validation like:
     if data['field1']>123 and data['field2']<234:
         errors.append('something is wrong')

     # errors is either empty list (as returned by form.validate)
     # or list filled with errors
     # We shouldn't return None here because this would cause
     # form.validate to be called again in handleSubmit method
     return errors


I had one more issue with subclassing and actions.
If you're subclassing from a class that has some actions already defined
and you want to add new actions, eg. you want to have Edit form with
additional 'Cancel' action, then it is necessary to do something like
that:

class MyNewEditForm(EditForm):
    actions = EditForm.actions

    (...)

    @action(_'Cancel')
    def handler...

I mean line:
    actions = EditForm.actions

Otherwise 'Edit' action will be not available.

Not much to do to get inherited actions back but surprising...


-- 
Maciej Wisniowski


More information about the Zope3-dev mailing list