[Zope-CMF] Validation during object creation

Dieter Maurer dieter@handshake.de
Mon, 8 Jul 2002 20:23:24 +0200


Geoff Davis writes:
 > ...
 > I have a class of objects called MyObject that I want to manage.  To create
 > such a MyObject, one invokes a python method called addMyObject.
 > addMyObject initially sets some values and passes them to a ZPT called
 > addMyObjectForm.  The form submits to addMyObject.  addMyObject then
 > validates the parameters -- if they are invalid, it passes the user's
 > responses back to addMyObjectForm; if they are valid, it makes the
 > appropriate call to invokeFactory and then relocates to some other page.
 > 
 > A few questions:
 > 
 > 1) Before I reinvent a wheel, is there already an easy way to do this in
 > Zope?  I haven't seen anything yet
CMFFormulator may help you with the validation.

Otherwise, your approach seems to be very easy, only a few lines
of Python code. Do not expect complex solutions for simple problems...

 > ...
 > I have been trying to add addMyObject as an external method, but have been
 > encountering weird errors that I think are arising from
 > ValidatedForm.__call__ not having the right function signature.  Given that
 > ExternalMethod seems to expect a method with the signature foo(self), I'm
 > not sure how to write an appropriate __call__ signature (__call__(self,
 > self)??).  Any ideas?  The specific error I'm getting is on line 143 of
 > ExternalMethod.py (in Zope 2.5.1): ff doesn't have an attribute
 > func_defaults.
External Methods do not have a fixed signature.

There is some magic, if you have a first parameter called "self".
Under some circumstances, e.g. when called via the Web,
the context object (in the sense of Python Scripts) is passed automatically
via this "self" parameter. If you want to read more, look at
the Zope book or

  <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>

The error above seems to indicate, that what you think is a function
is something different.


Dieter