Added getForCurrentAccount to user.Logic
authorSverre Rabbelier <srabbelier@gmail.com>
Fri, 12 Dec 2008 00:34:39 +0000
changeset 722 a59eaa177562
parent 721 6f1d29857072
child 723 69e5130e4a0a
Added getForCurrentAccount to user.Logic It returns the user entity associated with the currently logged in user. Patch by: Sverre Rabbelier
app/soc/logic/models/user.py
--- a/app/soc/logic/models/user.py	Fri Dec 12 00:34:12 2008 +0000
+++ b/app/soc/logic/models/user.py	Fri Dec 12 00:34:39 2008 +0000
@@ -22,6 +22,8 @@
   ]
 
 
+from google.appengine.api import users
+
 from soc.logic.helper import notifications
 from soc.logic.models import base
 
@@ -54,6 +56,22 @@
 
     return False
 
+  def getForCurrentAccount(self):
+    """Retrieves the user entity for the currently logged in account
+
+    If there is no user logged in, or they have no associated User
+    entity, None is returend.
+    """
+
+    account = users.get_current_user()
+
+    if not account:
+      return None
+
+    user = self.getForFields({'account': account}, unique=True)
+
+    return user
+
   def getKeyValues(self, entity):
     """See base.Logic.getKeyValues.
     """