Factor out the getForAccount logic in user
Also normalize the account before retrieving it.
Patch by: Sverre Rabbelier
--- a/app/soc/logic/models/user.py Thu Feb 26 16:54:08 2009 +0000
+++ b/app/soc/logic/models/user.py Thu Feb 26 16:54:44 2009 +0000
@@ -26,6 +26,7 @@
from google.appengine.ext import db
from soc.cache import sidebar
+from soc.logic import accounts
from soc.logic.helper import notifications
from soc.logic.models import base
from soc.logic.models.site import logic as site_logic
@@ -72,10 +73,26 @@
if not account:
return None
- user = self.getForFields({'account': account, 'status':'valid'},
- unique=True)
+ return self.getForAccount(account)
+
+ def getForAccount(self, account):
+ """Retrieves the user entity for the specified account.
+
+ If there is no user logged in, or they have no valid associated User
+ entity, None is returned.
+ """
- return user
+ if not account:
+ raise base.InvalidArgumentError
+
+ account = accounts.normalizeAccount(account)
+
+ fields = {
+ 'account': account,
+ 'status':'valid',
+ }
+
+ return self.getForFields(filter=fields, unique=True)
def agreesToSiteToS(self, entity):
"""Returns indication of User's answer to the site-wide Terms of Service.