changeset 475:9dd38344c466 celery

Added validation for uniq email address
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 13 Sep 2010 01:38:14 +0200
parents a3d9d24acbec
children 8ba65e4c4e4c
files pylons_app/model/forms.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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