Hi all,
I have an edit form:
class claimEditForm(form.EditForm):
   form_fields = form.Fields(Iclaim).omit('__name__', '__parent__')

@form.action(_("MyApply"), condition=form.haveInputWidgets) def handle_edit_action(self, action, data):
       if self.context.modify(data):
           self.status = _(u"Object Updated")
           self.status = _(u"No Changes")

The object has a modify method, which looks like this:
   def modify(self, kw):
       fieldnames = getFieldNames(Iclaim)
       for k in kw.keys():
           if k not in fieldnames:
               raise Invalid("Invalid Field to set: %s", k)
               field = Iclaim[k]
               setattr(self, k, kw[k])
self._completeValues() ###This method calculates some missing data for the object (if possible) or raises an error
       return True

The thing I don't understand is this: The invariant method I have in the interface is being called twice.

First Pass through, object passed to my invariant is of type:
   FormData: <zope.formlib.form.FormData instance at 0x3f07c10>

Call stack is:
debug_call [publish.py:114] __call__ [form.py:773] update [form.py:740] handleSubmit [form.py:683] validate [form.py:720] checkInvariants [form.py:504] validateInvariants [interface.py:583] claimInvariants [interfaces.py:39]

(In certain cases the data will be invalid, because I need to prep a few fields via claim._completeValues() )

Second Pass through, object passed to my invariant function is of type:
   claim: <as.claim.claim.claim object at 0x3591770>

Call stack is:
debug_call [publish.py:114] __call__ [form.py:773] update [form.py:754] success [form.py:598] handle_edit_action [forms.py:23] (This is my action being called now!) modify [claim.py:42] (At this point in the code, the as.claim.claim.claim object has been modified with the contents of the form) validateInvariants [interface.py:583] claimInvariants [interfaces.py:39] My question is: In order to not have the variants checked before my data is prepped, should I really be using a form.EditForm as the base, or some other class?

Many thanks in advance, and a happy new year

Zope3-users mailing list

Reply via email to