> I'm using zope.formlib.form.EditFormBase and want to normalize data
> before saving it.
> Saving is done by the applyChanges function which is called from
> The problem is that handle_edit_action is an action, so I can't easily
> subclass and do a super call to handle_edit_action.
> If I add my own handle_edit_action I have to copy-paste the code from
> formlib because applyChanges is a function, not a method on the class.
What code you have to copy-paste from formlib when you add your own
I think it is common to do something like:
from zope.formlib import form
> My solution would be to add an applyChanges method to
> zope.formlib.form.EditFormBase which calls the applyChanges function.
> Any objections?
Possibly a lot of existing code uses form.applyChanges as in example
above so this may be a compatibility problem.
For me it would be better to change handleSubmit method
and the way action.validate is called there.
Currently action.validate method can be used to add some values to
'data' dictionary but not to simply validate form values because 'data'
parameter is an empty dictionary when 'validate' is called.
I'd like to have action.validate called with 'data' dictionary that is
already filled with values.
I mean that handleSubmit function may be changed to something like:
def handleSubmit(actions, data, default_validate=None):
for action in actions:
# ------------ default_validate is called before
errors = default_validate(action, data)
if errors is None:
errors = action.validate(data)
return errors, action
return None, None
This way validate gets 'data' parameter that already has
values from widgets, these values may be simply validated and/or
normalized. There is even no need to change edit action.
Zope3-dev mailing list