<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Once more, with formatting:<br>
<br>
Hi all,&nbsp; <br>
<br>
I have an edit form:
<br>
<blockquote><tt>class claimEditForm(form.EditForm):
  <br>
&nbsp;&nbsp; form_fields = form.Fields(Iclaim).omit('__name__', '__parent__')
  <br>
  <br>
&nbsp;&nbsp; @form.action(_("MyApply"), condition=form.haveInputWidgets)&nbsp;&nbsp; &nbsp;&nbsp; <br>
&nbsp;&nbsp; def handle_edit_action(self, action, data):
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.context.modify(data):
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.status = _(u"Object Updated")
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.status = _(u"No Changes")
  <br>
  </tt></blockquote>
<br>
The object has a modify method, which looks like this:
<br>
<br>
<blockquote>&nbsp;&nbsp;<tt> def modify(self, kw):
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fieldnames = getFieldNames(Iclaim)
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for k in kw.keys():
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if k not in fieldnames:
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise Invalid("Invalid Field to set: %s", k)
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; field = Iclaim[k]
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; field.validate(kw[k])
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setattr(self, k, kw[k])
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self._completeValues() ###This method calculates some missing
data for the &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ###object (if possible)
or raises an error
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Iclaim.validateInvariants(self)
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return True
  </tt><br>
</blockquote>
<br>
The thing I don't understand is this: The invariant method I have in
the interface is being called twice.
<br>
<br>
First Pass through, object passed to my invariant is of type:
<br>
&nbsp;&nbsp; <tt>FormData: &lt;zope.formlib.form.FormData instance at
0x3f07c10&gt;
<br>
</tt><br>
Call stack is:
<br>
<tt>&nbsp;&nbsp; debug_call [publish.py:114]<br>
&nbsp;&nbsp; &nbsp;&nbsp; __call__ [form.py:773]<br>
&nbsp;&nbsp; &nbsp;&nbsp; update [form.py:740]<br>
&nbsp;&nbsp; &nbsp;&nbsp; handleSubmit [form.py:683]<br>
&nbsp;&nbsp; &nbsp;&nbsp; validate [form.py:720]<br>
&nbsp;&nbsp; &nbsp;&nbsp; checkInvariants [form.py:504]<br>
&nbsp;&nbsp; &nbsp;&nbsp; validateInvariants [interface.py:583]<br>
&nbsp;&nbsp; &nbsp;&nbsp; claimInvariants [interfaces.py:39]
<br>
</tt><br>
(In certain cases the data will be invalid, because I need to prep a
few fields via claim._completeValues() )
<br>
<br>
Second Pass through, object passed to my invariant function is of type:
<br>
&nbsp;&nbsp; <tt>claim: &lt;as.claim.claim.claim object at 0x3591770&gt;
</tt><br>
<br>
Call stack is:
<br>
<blockquote><tt>&nbsp;&nbsp; debug_call [publish.py:114]</tt><br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; __call__ [form.py:773]</tt><br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; update [form.py:754]</tt><br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; success [form.py:598]</tt><br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; handle_edit_action [forms.py:23] </tt>(This is my action
being called now!) <br>
  <tt>&nbsp;&nbsp; &nbsp;&nbsp; modify [claim.py:42] </tt>(At this point in the code, the
as.claim.claim.claim object has been modified with the contents of the
form)<br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; validateInvariants [interface.py:583]</tt><br>
  <tt>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; claimInvariants [interfaces.py:39]&nbsp;&nbsp;&nbsp; &nbsp;
  </tt><br>
</blockquote>
<br>
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?
<br>
<br>
Many thanks in advance, and a happy new year
<br>
Adam
<br>
<br>
<br>
<br>
</body>
</html>