# HG changeset patch # User Sverre Rabbelier # Date 1235667284 0 # Node ID bb086732bf7f803b73a833c3e60889d6395cf886 # Parent ac407f5b10dc54301f4eccf0f5c2e4af6fd7c60a Factor out the getForAccount logic in user Also normalize the account before retrieving it. Patch by: Sverre Rabbelier diff -r ac407f5b10dc -r bb086732bf7f app/soc/logic/models/user.py --- 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.