[Zope3-Users] Invariants and forms
Darryl Cousins
darryl at darrylcousins.net.nz
Mon Aug 13 06:01:56 EDT 2007
Hi,
This was answered recently me thinks.
http://mail.zope.org/pipermail/zope3-users/2007-August/006648.html
Regards,
Darryl
On Mon, 2007-08-13 at 11:37 +0200, NYLAN at gmx.net wrote:
> Hello, I'm using an invariant to check if given passwords are equal.
>
> I've found two different examples(see below), but both don't display my given exception message. The only thing i get is the standard error message.
>
> Since this is my first experience with zope, could someone explain to me the correct way to get a custom error message with invariants?
>
> Thanks!!!
> I'm using zope version 3.3.1.
>
> First example
> (taken from: http://blog.gocept.com/zope3-testen-von-felderuebergreifenden-bedingungen-in-interfaces-mit-zope-formlib/):
>
> class PasswordsAreNotEqual(zope.schema.ValidationError):
> u"""Das Passwort und die Wiederholung sind nicht gleich."""
> zope.interface.implements(zope.app.form.interfaces.IWidgetInputError)
>
> def arePasswordsEqual(obj)
> if obj.password != obj.password2:
> raise PasswordsAreNotEqual
>
> from zope.interface import Interface, invariant
>
> class IUser(Interface):
> password = zope.schema.Password(title=u"Passwort")
> password2 = zope.schema.Password(title=u"Wiederholung des Passworts")
>
> arePasswordsEqual = invariant(arePasswordsEqual)
>
>
> Second example
> (taken from:
> http://blog.gocept.com/zope3-testen-von-felderuebergreifenden-bedingungen-invariants-in-interfaces-mit-zope-formlib-aktualisiert)
>
> import zope.interface
>
> class IUser(zope.interface.Interface):
> password = zope.schema.Password(title=u"Passwort")
> password2 = zope.schema.Password(title=u"Wiederholung des Passworts")
>
> @zope.interface.invariant
> def arePasswordsEqual(user):
> if user.password != user.password2:
> raise zope.interface.Invalid(
> u"""Das Passwort und die Wiederholung sind nicht gleich.""")
More information about the Zope3-users
mailing list