Handle GAE account normalization
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 07 Feb 2009 20:42:28 +0000
changeset 1242 c5ca70606850
parent 1241 5e25cd6abe09
child 1243 ccd791a899b3
Handle GAE account normalization Also forbid users from going back to a former account. Patch by: Sverre Rabbelier
app/soc/logic/cleaning.py
app/soc/logic/models/user.py
--- a/app/soc/logic/cleaning.py	Sat Feb 07 20:40:48 2009 +0000
+++ b/app/soc/logic/cleaning.py	Sat Feb 07 20:42:28 2009 +0000
@@ -216,7 +216,7 @@
   """
   def wrapper(self):
     cleaned_data = self.cleaned_data
-    
+
     link_id = cleaned_data.get(link_id_field)
     user_account = cleaned_data.get(account_field)
 
@@ -229,8 +229,7 @@
       former_accounts = user_entity.former_accounts
 
       # if it's not the user's current account or one of his former accounts
-      if (user_entity.account != user_account  and 
-          user_account not in former_accounts):
+      if user_entity.account != user_account:
 
         # get the user having the given account
         fields = {'account': user_account}
--- a/app/soc/logic/models/user.py	Sat Feb 07 20:40:48 2009 +0000
+++ b/app/soc/logic/models/user.py	Sat Feb 07 20:42:28 2009 +0000
@@ -54,8 +54,9 @@
         'WHERE former_accounts != :1', None).fetch(1000)
 
     for former_account_user in users_with_former_accounts: 
-      if account in former_account_user.former_accounts:
-        return True
+      for former_account in former_account_user.former_accounts:
+        if str(account) == str(former_account):
+          return True
 
     return False
 
@@ -153,7 +154,7 @@
     if (name == 'agreed_to_tos') and (entity.agreed_to_tos != value):
       sidebar.flush(entity.account)
 
-    if (name == 'account') and (entity.account != value):
+    if (name == 'account') and (str(entity.account) != str(value)):
       entity.former_accounts.append(entity.account)
 
     return True