<!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, <br>
<br>
I have an edit form:
<br>
<blockquote><tt>class claimEditForm(form.EditForm):
<br>
form_fields = form.Fields(Iclaim).omit('__name__', '__parent__')
<br>
<br>
@form.action(_("MyApply"), condition=form.haveInputWidgets) <br>
def handle_edit_action(self, action, data):
<br>
if self.context.modify(data):
<br>
self.status = _(u"Object Updated")
<br>
else:
<br>
self.status = _(u"No Changes")
<br>
</tt></blockquote>
<br>
The object has a modify method, which looks like this:
<br>
<br>
<blockquote> <tt> def modify(self, kw):
<br>
fieldnames = getFieldNames(Iclaim)
<br>
for k in kw.keys():
<br>
if k not in fieldnames:
<br>
raise Invalid("Invalid Field to set: %s", k)
<br>
else:
<br>
field = Iclaim[k]
<br>
field.validate(kw[k])
<br>
setattr(self, k, kw[k])
<br>
self._completeValues() ###This method calculates some missing
data for the ###object (if possible)
or raises an error
<br>
Iclaim.validateInvariants(self)
<br>
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>
<tt>FormData: <zope.formlib.form.FormData instance at
0x3f07c10>
<br>
</tt><br>
Call stack is:
<br>
<tt> debug_call [publish.py:114]<br>
__call__ [form.py:773]<br>
update [form.py:740]<br>
handleSubmit [form.py:683]<br>
validate [form.py:720]<br>
checkInvariants [form.py:504]<br>
validateInvariants [interface.py:583]<br>
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>
<tt>claim: <as.claim.claim.claim object at 0x3591770>
</tt><br>
<br>
Call stack is:
<br>
<blockquote><tt> debug_call [publish.py:114]</tt><br>
<tt> __call__ [form.py:773]</tt><br>
<tt> update [form.py:754]</tt><br>
<tt> success [form.py:598]</tt><br>
<tt> handle_edit_action [forms.py:23] </tt>(This is my action
being called now!) <br>
<tt> 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> validateInvariants [interface.py:583]</tt><br>
<tt> claimInvariants [interfaces.py:39]
</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>