Cecil Westerhof schrieb:
> 2008/5/3 Paul Johnston <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>:
> The built-in validators don't interface with the database, but you
> can certainly write your own.
>
> Any pointers about how to do this? I am just using TG for a week, so I
> am a little blank on the subject.
Here's a simple example:
class UniqueEmail(validators.FancyValidator):
"""Validator to confirm a given email address is unique."""
messages = {
'notUnique': u'This email address is already registered with '
u'another account.'
}
def _to_python(self, value, state):
# Assuming you defined a function to check uniqueness of
# an email address in your model module
if not model.email_is_unique(value):
raise validators.Invalid(self.message('notUnique', state),
value, state)
return value
Some doc links:
- How to write your own validators:
http://formencode.org/Validator.html#writing-your-own-validator
- Applied to TurboGears: http://tinyurl.com/655szz
- How to pass state to a validator: http://tinyurl.com/5be7et
HTH, Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---