# HG changeset patch # User Marcin Kuzminski # Date 1284334694 -7200 # Node ID 9dd38344c466552f5e1486b518a11df94ebfb670 # Parent a3d9d24acbecc91c2f5f07c3dae672621eff0d3a Added validation for uniq email address diff -r a3d9d24acbec -r 9dd38344c466 pylons_app/model/forms.py --- a/pylons_app/model/forms.py Mon Sep 13 01:27:41 2010 +0200 +++ b/pylons_app/model/forms.py Mon Sep 13 01:38:14 2010 +0200 @@ -209,6 +209,19 @@ raise formencode.Invalid(msg, value, state, error_dict={'paths_root_path':msg}) +class UniqSystemEmail(formencode.validators.FancyValidator): + def to_python(self, value, state): + sa = meta.Session + try: + user = sa.query(User).filter(User.email == value).scalar() + if user: + raise formencode.Invalid(_("That e-mail address is already taken") , + value, state) + finally: + meta.Session.remove() + + return value + class ValidSystemEmail(formencode.validators.FancyValidator): def to_python(self, value, state): sa = meta.Session @@ -263,7 +276,7 @@ active = StringBoolean(if_missing=False) name = UnicodeString(strip=True, min=3, not_empty=True) lastname = UnicodeString(strip=True, min=3, not_empty=True) - email = Email(not_empty=True) + email = All(Email(not_empty=True), UniqSystemEmail()) return _UserForm