diff pylons_app/model/forms.py @ 489:460ad816820d celery

fixed bug when new repo had no last commiter, fixed bug when my_account updating information failed, by not uniq email address.
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 20 Sep 2010 22:47:20 +0200
parents 9dd38344c466
children 74b9bed279ae
line wrap: on
line diff
--- a/pylons_app/model/forms.py	Sun Sep 19 03:42:48 2010 +0200
+++ b/pylons_app/model/forms.py	Mon Sep 20 22:47:20 2010 +0200
@@ -209,18 +209,22 @@
         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 
+def UniqSystemEmail(old_data):
+    class _UniqSystemEmail(formencode.validators.FancyValidator):
+        def to_python(self, value, state):
+            if old_data['email'] != value:
+                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
+        
+    return _UniqSystemEmail
     
 class ValidSystemEmail(formencode.validators.FancyValidator):
     def to_python(self, value, state):
@@ -276,7 +280,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 = All(Email(not_empty=True), UniqSystemEmail())
+        email = All(Email(not_empty=True), UniqSystemEmail(old_data))
         
     return _UserForm