app/soc/logic/models/user.py
changeset 2345 f78caf12f32d
parent 1600 0aa3de1b2acc
child 2361 40b0c25a5793
equal deleted inserted replaced
2344:621252e2cc18 2345:f78caf12f32d
    73     if not account:
    73     if not account:
    74       return None
    74       return None
    75 
    75 
    76     return self.getForAccount(account)
    76     return self.getForAccount(account)
    77 
    77 
       
    78   def getForCurrentUserId(self):
       
    79     """Retrieves the user entity for the currently logged in user id.
       
    80 
       
    81     If there is no user logged in, or they have no valid associated User
       
    82     entity, None is returned.
       
    83     """
       
    84 
       
    85     user_id = accounts.getCurrentUserId()
       
    86 
       
    87     if not user_id:
       
    88       return None
       
    89 
       
    90     return self.getForUserId(user_id)
       
    91 
    78   def getForAccount(self, account):
    92   def getForAccount(self, account):
    79     """Retrieves the user entity for the specified account.
    93     """Retrieves the user entity for the specified account.
    80 
    94 
    81     If there is no user logged in, or they have no valid associated User
    95     If there is no user logged in, or they have no valid associated User
    82     entity, None is returned.
    96     entity, None is returned.
    87 
   101 
    88     account = accounts.normalizeAccount(account)
   102     account = accounts.normalizeAccount(account)
    89 
   103 
    90     fields = {
   104     fields = {
    91         'account': account,
   105         'account': account,
       
   106         'status':'valid',
       
   107         }
       
   108 
       
   109     return self.getForFields(filter=fields, unique=True)
       
   110 
       
   111   def getForUserId(self, user_id):
       
   112     """Retrieves the user entity for the specified user id.
       
   113 
       
   114     If there is no user logged in, or they have no valid associated User
       
   115     entity, None is returned.
       
   116     """
       
   117 
       
   118     if not user_id:
       
   119       raise base.InvalidArgumentError
       
   120 
       
   121     fields = {
       
   122         'user_id': user_id,
    92         'status':'valid',
   123         'status':'valid',
    93         }
   124         }
    94 
   125 
    95     return self.getForFields(filter=fields, unique=True)
   126     return self.getForFields(filter=fields, unique=True)
    96 
   127