app/soc/logic/site/id_user.py
changeset 223 a18e93e21672
parent 202 b8b4a83788d4
child 229 a46c238be8db
equal deleted inserted replaced
222:63e5f42e2e83 223:a18e93e21672
    65     # id not initialized, so check if a Google Account is currently logged in
    65     # id not initialized, so check if a Google Account is currently logged in
    66     id = users.get_current_user()
    66     id = users.get_current_user()
    67 
    67 
    68   return id
    68   return id
    69 
    69 
       
    70 
    70 def getUsersForOffsetAndLimit(offset=0, limit=0):
    71 def getUsersForOffsetAndLimit(offset=0, limit=0):
    71   """Returns Users entities for given offset and limit or None if not found.
    72   """Returns Users entities for given offset and limit or None if not found.
    72     
    73     
    73   Args:
    74   Args:
    74     offset: offset in entities list which defines first entity to return
    75     offset: offset in entities list which defines first entity to return
    77   query = db.GqlQuery('SELECT * FROM User ORDER BY id')
    78   query = db.GqlQuery('SELECT * FROM User ORDER BY id')
    78 
    79 
    79   # Fetch one more to see if there should be a 'next' link
    80   # Fetch one more to see if there should be a 'next' link
    80   return query.fetch(limit+1, offset)  
    81   return query.fetch(limit+1, offset)  
    81 
    82 
       
    83 
    82 def getUserFromId(id):
    84 def getUserFromId(id):
    83   """Returns User entity for a Google Account, or None if not found.  
    85   """Returns User entity for a Google Account, or None if not found.  
    84     
    86     
    85   Args:
    87   Args:
    86     id: a Google Account (users.User) object
    88     id: a Google Account (users.User) object
    87   """
    89   """
    88   return soc.models.user.User.gql('WHERE id = :1', id).get()
    90   return soc.models.user.User.gql('WHERE id = :1', id).get()
       
    91 
    89 
    92 
    90 def getUserIfMissing(user, id):
    93 def getUserIfMissing(user, id):
    91   """Conditionally returns User entity for a Google Account.
    94   """Conditionally returns User entity for a Google Account.
    92   
    95   
    93   This function is used to look up the User entity corresponding to the
    96   This function is used to look up the User entity corresponding to the
   184     return False
   187     return False
   185   
   188   
   186   return user.is_developer
   189   return user.is_developer
   187 
   190 
   188 
   191 
   189 LINKNAME_PATTERN = r'''(?x)
   192 LINKNAME_REGEX = re.compile(key_name.LINKNAME_PATTERN)
   190     ^
       
   191     [0-9a-z]   # start with ASCII digit or lowercase
       
   192     (
       
   193      [0-9a-z]  # additional ASCII digit or lowercase
       
   194      |         # -OR-
       
   195      _[0-9a-z] # underscore and ASCII digit or lowercase
       
   196     )*         # zero or more of OR group
       
   197     $
       
   198 '''
       
   199 
       
   200 LINKNAME_REGEX = re.compile(LINKNAME_PATTERN)
       
   201 
   193 
   202 def isLinkNameFormatValid(link_name):
   194 def isLinkNameFormatValid(link_name):
   203   """Returns True if link_name is in a valid format.
   195   """Returns True if link_name is in a valid format.
   204   
   196   
   205   Args:
   197   Args: