# HG changeset patch # User Marcin Kuzminski # Date 2010-09-12 23:38:14 # Node ID 9dd38344c466552f5e1486b518a11df94ebfb670 # Parent a3d9d24acbecc91c2f5f07c3dae672621eff0d3a Added validation for uniq email address diff --git a/pylons_app/model/forms.py b/pylons_app/model/forms.py --- a/pylons_app/model/forms.py +++ b/pylons_app/model/forms.py @@ -209,6 +209,19 @@ class ValidPath(formencode.validators.Fa 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 @@ def UserForm(edit=False, old_data={}): 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