[Grok-dev] Form data validation
Sebastian Ware
sebastian at urbantalk.se
Wed Mar 9 13:55:43 EST 2011
When you have a constraint in an interface, you only get passed the value of that field, not the actual object. You could use an invariant which gets passed the actual object:
@interface.invariant
def passwordConfirm(user):
if (user.password != user.password_confirmation):
raise interface.Invalid(u'The password and confirmation do not match.')
then you can create a field index for "uid" and do a search in the index.
http://grok.zope.org/documentation/how-to/implementing-search
Mvh Sebastian
8 mar 2011 kl. 16.37 skrev Lumir Jasiok:
> Hi,
>
> I am trying to figure out how to validate form data against ZODB's data.
> I have Employees model, data saved into the ZODB.
> Inside IEmployee interface is field uid. I need to be sure, that uid is
> unique, so I add "constraint=unique_uid" parameter.
>
> How can I from function unique_uid check if Employee's uid is unique or
> not? Or there is another, better way to doit?
>
> class IEmployee(interface.Interface):
> first_name = schema.TextLine(title=u'First name', required=True)
> last_name = schema.TextLine(title=u'Last name', required=True)
> uid = schema.TextLine(title=u'Personal Number', required=True,
> constraint=unique_uid)
>
> def unique_uid(uid):
> ...?
>
> Thanks for help
>
> Lumir
>
> --
> Lumír Jasiok
> VSB-TU Ostrava - Computer centre
> Tel: +420 59 732 3189
> E-mail: lumir.jasiok at vsb.cz
> http://www.vsb.cz
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
More information about the Grok-dev
mailing list