app/soc/logic/site/id_user.py
author Todd Larsen <tlarsen@google.com>
Thu, 02 Oct 2008 20:22:15 +0000
changeset 262 52a42831d9d6
parent 245 b14c2c4d3484
child 263 9b39d93b677f
permissions -rw-r--r--
Factor out an isIdAvailable() function from EditForm.clean_id() in soc/views/site/user/profile.py and add it to soc/logic/site/id_user.py. Addresses some comments on r614. Patch by: Todd Larsen Review by: Pawel Solyga Review URL: http://codereviews.googleopensourceprograms.com/1202
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Basic ID (Google Account) and User (Model) query functions.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
229
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
    21
  '"Chen Lunpeng" <forever.clp@gmail.com>',
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  '"Todd Larsen" <tlarsen@google.com>',
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  ]
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    26
import re
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    27
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
from google.appengine.api import users
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    29
from google.appengine.ext import db
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents: 184
diff changeset
    31
from soc.logic import key_name
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
from soc.logic import out_of_band
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
import soc.models.user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    37
def getUserKeyNameFromId(id):
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    38
  """Return a Datastore key_name for a User derived from a Google Account.
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    39
  
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    40
  Args:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    41
    id: a Google Account (users.User) object
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    42
  """
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    43
  if not id:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    44
    return None
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    45
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents: 184
diff changeset
    46
  return key_name.nameUser(id.email())
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    47
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    48
184
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    49
def getIdIfMissing(id=None):
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
  """Gets Google Account of logged-in user (possibly None) if id is false.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
  
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
  This is a convenience function that simplifies a lot of view code that
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  accepts an optional id argument from the caller (such as one looked up
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
  already by another view that decides to "forward" the request to this
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  other view).
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
  Args:
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    58
    id: a Google Account (users.User) object, or None
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
  Returns:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
    If id is non-false, it is simply returned; otherwise, the Google Account
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
    of currently logged-in user is returned (which could be None if no user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
    is logged in).
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
  """
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
  if not id:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
    # id not initialized, so check if a Google Account is currently logged in
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
    id = users.get_current_user()
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
  return id
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
223
a18e93e21672 Use the LINKNAME_PATTERN from its new home in key_name.py. Also, add some
Todd Larsen <tlarsen@google.com>
parents: 202
diff changeset
    71
184
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    72
def getUsersForOffsetAndLimit(offset=0, limit=0):
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    73
  """Returns Users entities for given offset and limit or None if not found.
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    74
    
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    75
  Args:
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    76
    offset: offset in entities list which defines first entity to return
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    77
    limit: max amount of entities to return
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    78
  """
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    79
  query = db.GqlQuery('SELECT * FROM User ORDER BY id')
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    80
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    81
  # Fetch one more to see if there should be a 'next' link
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    82
  return query.fetch(limit+1, offset)  
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    83
223
a18e93e21672 Use the LINKNAME_PATTERN from its new home in key_name.py. Also, add some
Todd Larsen <tlarsen@google.com>
parents: 202
diff changeset
    84
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    85
def getUserFromId(id):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    86
  """Returns User entity for a Google Account, or None if not found.  
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    87
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    88
  Args:
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
    89
    id: a Google Account (users.User) object
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    90
  """
184
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
    91
  return soc.models.user.User.gql('WHERE id = :1', id).get()
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    92
223
a18e93e21672 Use the LINKNAME_PATTERN from its new home in key_name.py. Also, add some
Todd Larsen <tlarsen@google.com>
parents: 202
diff changeset
    93
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    94
def getUserIfMissing(user, id):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    95
  """Conditionally returns User entity for a Google Account.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    96
  
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    97
  This function is used to look up the User entity corresponding to the
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    98
  supplied Google Account *if* the user parameter is false (usually None).
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    99
  This function is basically a no-op if user already refers to a User
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   100
  entity.  This is a convenience function that simplifies a lot of view
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   101
  code that accepts an optional user argument from the caller (such as
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   102
  one looked up already by another view that decides to "forward" the
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   103
  HTTP request to this other view).
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   104
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   105
  Args:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   106
    user: None (usually), or an existing User entity
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   107
    id: a Google Account (users.User) object
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   108
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   109
  Returns:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   110
    * user (which may have already been None if passed in that way by the
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   111
      caller) if id is false or user is non-false
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   112
    * results of getUserFromId() if user is false and id is non-false
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   113
  """
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   114
  if id and (not user):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   115
    # Google Account supplied and User uninitialized, so look up User entity
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   116
    user = getUserFromId(id)
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   117
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   118
  return user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   119
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   120
229
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   121
def getNearestUsers(id=None, link_name=None):
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   122
  """Get User entities just before and just after the specified User.
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   123
    
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   124
  Args:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   125
    id: a Google Account (users.User) object; default is None (not supplied)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   126
    link_name: link name string; default is None (not supplied)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   127
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   128
  Returns:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   129
    User entities being those just before and just after the (possibly
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   130
    non-existent) User for given id or link_name,
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   131
      OR
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   132
    possibly None if query had no results or neither id or link_name were
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   133
    supplied.
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   134
  """
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   135
  if id:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   136
    query = db.GqlQuery("SELECT * FROM User WHERE id > :1", id)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   137
    return query.fetch(1)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   138
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   139
  #if id not supplied, try link name.
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   140
  if link_name:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   141
    query = db.GqlQuery("SELECT * FROM User WHERE link_name > :1", link_name)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   142
    return query.fetch(1)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   143
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   144
  return None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   145
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   146
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   147
def findNearestUsersOffset(width, id=None, link_name=None):
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   148
  """Finds offset of beginning of a range of Users around the nearest User.
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   149
  
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   150
  Args:
230
cb2c7ae5424d Fix typo in findNearestUsersOffset() __doc__ string missed in r661.
Todd Larsen <tlarsen@google.com>
parents: 229
diff changeset
   151
    width: the width of the "found" window around the nearest User found 
229
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   152
    id: a Google Account (users.User) object, or None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   153
    link_name: link name input in the Lookup form or None if not supplied.
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   154
    
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   155
  Returns:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   156
    an offset into the list of Users that is width/2 less than the
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   157
    offset of the first User returned by getNearestUsers(), or zero if
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   158
    that offset would be less than zero
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   159
      OR
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   160
    None if there are no nearest Users or the offset of the beginning of
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   161
    the range cannot be found for some reason 
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   162
  """
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   163
  # find User "nearest" to supplied id (Google Account) or link_name
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   164
  nearest_users = getNearestUsers(id=id, link_name=link_name)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   165
  
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   166
  if not nearest_users:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   167
    # no "nearest" User, so indicate that with None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   168
    return None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   169
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   170
  nearest_user = nearest_users[0]
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   171
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   172
  # start search for beginning of nearest Users range at offset zero
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   173
  offset = 0
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   174
  users = getUsersForOffsetAndLimit(offset=offset, limit=width)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   175
  
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   176
  while True:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   177
    for user in users:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   178
      if nearest_user.id == user.id:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   179
        # nearest User found in current search range, so return a range start
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   180
        return max(0, (offset - (width/2)))
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   181
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   182
      offset = offset + 1
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   183
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   184
    # nearest User was not in the current search range, so fetch the next set
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   185
    users = getUsersForOffsetAndLimit(offset=offset, limit=width)
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   186
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   187
    if not users:
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   188
      # nearest User never found, so indicate that with None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   189
      break
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   190
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   191
  return None
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   192
a46c238be8db Show link to /site/user/list on /site/user/lookup when User is not found.
Todd Larsen <tlarsen@google.com>
parents: 223
diff changeset
   193
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   194
def doesUserExist(id):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   195
  """Returns True if User exists in the Datastore for a Google Account.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   196
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   197
  Args:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   198
    id: a Google Account object
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   199
  """
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   200
  if getUserFromId(id):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   201
    return True
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   202
  else:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   203
    return False
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   204
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   205
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   206
def isIdUser(id=None):
166
4d2cbd0ea977 Fixed too long lines and deleted unused imports in id_user.py.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 164
diff changeset
   207
  """Returns True if a Google Account has it's User entity in datastore.
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   208
141
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   209
  Args:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   210
    id: a Google Account (users.User) object; if id is not supplied,
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   211
      the current logged-in user is checked
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   212
  """
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   213
  id = getIdIfMissing(id)
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   214
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   215
  if not id:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   216
    # no Google Account was supplied or is logged in
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   217
    return False
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   218
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   219
  user = getUserFromId(id)
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   220
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   221
  if not user:
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   222
    # no User entity for this Google Account
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   223
    return False
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   224
  
e120c24b89e2 Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 138
diff changeset
   225
  return True
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   226
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   227
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   228
def isIdDeveloper(id=None):
164
afdf502c6cc4 Documentation updates and one typo fix.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 141
diff changeset
   229
  """Returns True if a Google Account is a Developer with special privileges.
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   230
  
138
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   231
  Since it only works on the current logged-in user, if id matches the
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   232
  current logged-in Google Account, the App Engine Users API function
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   233
  user.is_current_user_admin() is checked.  If that returns False, or
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   234
  id is not the currently logged-in user, the is_developer property of
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   235
  the User entity corresponding to the id Google Account is checked next.
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   236
  
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   237
  This solves the "chicken-and-egg" problem of no User entity having its
e1167bdf71a4 Improve the __doc__ string of isIdDeveloper() to explain better how it now
Todd Larsen <tlarsen@google.com>
parents: 137
diff changeset
   238
  is_developer property set, but no one being able to set it.
137
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   239
  
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   240
  Args:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   241
    id: a Google Account (users.User) object; if id is not supplied,
137
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   242
      the current logged-in user is checked
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   243
  """
137
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   244
  id = getIdIfMissing(id)
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   245
 
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   246
  if not id:
137
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   247
    # no Google Account was supplied or is logged in, so an unspecified
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   248
    # User is definitely *not* a Developer
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   249
    return False
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   250
137
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   251
  if id == users.get_current_user():
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   252
    if users.is_current_user_admin():
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   253
      # supplied id is current logged-in user, and that user is in the
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   254
      # Administration->Developers list in the App Engine console
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   255
      return True
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   256
  
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   257
  user = getUserFromId(id)
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   258
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   259
  if not user:
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   260
    # no User entity for this Google Account, and id is not the currently
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   261
    # logged-in user, so there is no conclusive way to check the
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   262
    # Administration->Developers list in the App Engine console
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   263
    return False
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   264
  
0f572149449d Make isIdDeveloper() also able to check an is_developer Boolean property in
Todd Larsen <tlarsen@google.com>
parents: 136
diff changeset
   265
  return user.is_developer
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   266
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   267
262
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   268
def isIdAvailable(new_id, existing_user=None, existing_key_name=None):
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   269
  """Returns True if Google Account is available for use by existing User.
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   270
  
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   271
  Args:
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   272
    new_id: a Google Account (users.User) object with a (possibly) new email
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   273
    existing_user: an existing User entity; default is None, in which case
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   274
      existing_key_name is used to look up the User entity
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   275
    existing_key_name: the key_name of an existing User entity, used
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   276
      when existing_user is not supplied; default is None
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   277
  """
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   278
  if not existing_user:
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   279
    existing_user = getUserFromKeyName(existing_key_name)
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   280
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   281
  if existing_user:
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   282
    old_email = existing_user.id.email()
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   283
  else:
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   284
    old_email = None
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   285
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   286
  if new_id.email() == old_email:
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   287
    # "new" email is same as existing User wanting it, so it is "available"
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   288
    return True
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   289
  # else: "new" email truly is new to the existing User, so keep checking
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   290
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   291
  if not isIdUser(new_id):
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   292
    # new email address also does not belong to any other User,
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   293
    # so it is available
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   294
    return True
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   295
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   296
  # email does not already belong to this User, but to some other User
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   297
  return False
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   298
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   299
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   300
def getUserFromLinkName(link_name):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   301
  """Returns User entity for link_name or None if not found.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   302
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   303
  Args:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   304
    link_name: link name used in URLs to identify user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   305
  """
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   306
  return soc.models.user.User.gql('WHERE link_name = :1', link_name).get()
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   307
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   308
184
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   309
def getUserFromKeyName(key_name):
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   310
  """Returns User entity for key_name or None if not found.
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   311
    
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   312
  Args:
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   313
    key_name: key name of User entity
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   314
  """
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   315
  return soc.models.user.User.get_by_key_name(key_name)
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   316
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   317
112
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   318
def getUserIfLinkName(link_name):
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   319
  """Returns User entity for supplied link_name if one exists.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   320
  
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   321
  Args:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   322
    link_name: link name used in URLs to identify user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   323
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   324
  Returns:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   325
    * None if link_name is false.
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   326
    * User entity that has supplied link_name
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   327
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   328
  Raises:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   329
    out_of_band.ErrorResponse if link_name is not false, but no User entity
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   330
    with the supplied link_name exists in the Datastore
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   331
  """
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   332
  if not link_name:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   333
    # exit without error, to let view know that link_name was not supplied
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   334
    return None
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   335
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   336
  link_name_user = getUserFromLinkName(link_name)
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   337
    
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   338
  if link_name_user:
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   339
    # a User has this link name, so return that corresponding User entity
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   340
    return link_name_user
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   341
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   342
  # else: a link name was supplied, but there is no User that has it
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   343
  raise out_of_band.ErrorResponse(
4d9895fb15bc Consolidate functions dealing with Google Accounts and look-up of User entities
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
   344
      'There is no user with a "link name" of "%s".' % link_name, status=404)
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   345
135
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   346
136
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   347
def isLinkNameAvailableForId(link_name, id=None):
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   348
  """Indicates if link name is available for the given Google Account.
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   349
  
135
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   350
  Args:
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   351
    link_name: link name used in URLs to identify user
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   352
    id: a Google Account object; optional, current logged-in user will
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   353
      be used (or False will be returned if no user is logged in)
136
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   354
      
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   355
  Returns:
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   356
    True: the link name does not exist in the Datastore,
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   357
      so it is currently "available" to any User
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   358
    True: the link name exists and already belongs to the User entity
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   359
      associated with the specified Google Account
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   360
    False: the link name exists and belongs to a User entity other than
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   361
      that associated with the supplied Google Account
135
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   362
  """
136
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   363
  link_name_exists = doesLinkNameExist(link_name)
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   364
 
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   365
  if not link_name_exists:
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   366
    # if the link name does not exist, it is clearly available for any User
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   367
    return True
135
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   368
136
a95f511bfcf8 Replace checkLinkNameForId() with isLinkNameAvailableForId(), and implement
Todd Larsen <tlarsen@google.com>
parents: 135
diff changeset
   369
  return doesLinkNameBelongToId(link_name, id=id)
135
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   370
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   371
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   372
def doesLinkNameExist(link_name=None):
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   373
  """Returns True if link name exists in the Datastore.
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   374
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   375
  Args:
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   376
    link_name: link name used in URLs to identify user
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   377
  """
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   378
  if getUserFromLinkName(link_name):
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   379
    return True
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   380
  else:
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   381
    return False
a7ccde9d9eed Fixed one typo in response_helpers which caused is_admin context variable not to work correctly.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 131
diff changeset
   382
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   383
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   384
def doesLinkNameBelongToId(link_name, id=None):
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   385
  """Returns True if supplied link name belongs to supplied Google Account.
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   386
  
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   387
  Args:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   388
    link_name: link name used in URLs to identify user
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   389
    id: a Google Account object; optional, current logged-in user will
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   390
      be used (or False will be returned if no user is logged in)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   391
  """
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   392
  id = getIdIfMissing(id)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   393
    
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   394
  if not id:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   395
    # id not supplied and no Google Account logged in, so link name cannot
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   396
    # belong to an unspecified User
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   397
    return False
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   398
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   399
  user = getUserFromId(id)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   400
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   401
  if not user:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   402
    # no User corresponding to id Google Account, so no link name at all 
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   403
    return False
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   404
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   405
  if user.link_name != link_name:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   406
    # User exists for id, but does not have this link name
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   407
    return False
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   408
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   409
  return True  # link_name does actually belong to this Google Account
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   410
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   411
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   412
def updateOrCreateUserFromId(id, **user_properties):
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   413
  """Update existing User entity, or create new one with supplied properties.
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   414
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   415
  Args:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   416
    id: a Google Account object
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   417
    **user_properties: keyword arguments that correspond to User entity
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   418
      properties and their values
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   419
      
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   420
  Returns:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   421
    the User entity corresponding to the Google Account, with any supplied
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   422
    properties changed, or a new User entity now associated with the Google
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   423
    Account and with the supplied properties
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   424
  """
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   425
  # attempt to retrieve the existing User
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   426
  user = getUserFromId(id)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   427
  
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   428
  if not user:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   429
    # user did not exist, so create one in a transaction
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   430
    key_name = getUserKeyNameFromId(id)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   431
    user = soc.models.user.User.get_or_insert(
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   432
      key_name, id=id, **user_properties)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   433
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   434
  # there is no way to be sure if get_or_insert() returned a new User or
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   435
  # got an existing one due to a race, so update with user_properties anyway,
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   436
  # in a transaction
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   437
  return updateUserProperties(user, **user_properties)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   438
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   439
184
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   440
def updateUserForKeyName(key_name, **user_properties):
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   441
  """Update existing User entity for keyname with supplied properties.
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   442
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   443
  Args:
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   444
    key_name: key name of User entity
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   445
    **user_properties: keyword arguments that correspond to User entity
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   446
      properties and their values
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   447
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   448
  Returns:
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   449
    the User entity corresponding to the Google Account, with any supplied
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   450
    properties changed, or a new User entity now associated with the Google
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   451
    Account and with the supplied properties
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   452
  """
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   453
  # attempt to retrieve the existing User
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   454
  user = getUserFromKeyName(key_name)
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   455
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   456
  if not user:
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   457
    return None
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   458
  
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   459
  # there is no way to be sure if get_or_insert() returned a new User or
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   460
  # got an existing one due to a race, so update with user_properties anyway,
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   461
  # in a transaction
7c0b42aecd9b Add support for changing User id (Google Account email) in User Profile Developer view. Now user profile developer edit view includes hidden key_name field. Fix typo in user/profile.py. Show former user ids in lookup and edit User Profile Developer views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 166
diff changeset
   462
  return updateUserProperties(user, **user_properties)
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   463
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   464
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   465
def updateUserProperties(user, **user_properties):
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   466
  """Update existing User entity using supplied User properties.
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   467
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   468
  Args:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   469
    user: a User entity
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   470
    **user_properties: keyword arguments that correspond to User entity
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   471
      properties and their values
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   472
      
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   473
  Returns:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   474
    the original User entity with any supplied properties changed 
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   475
  """
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   476
  def update():
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   477
    return _unsafeUpdateUserProperties(user, **user_properties)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   478
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   479
  return db.run_in_transaction(update)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   480
245
b14c2c4d3484 Moved isLinkNameFormatValid function out of id_user module to new common module. This function is going to be used by other form validation functions that require to validate linkname (different kind of Groups, Programs etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 230
diff changeset
   481
131
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   482
def _unsafeUpdateUserProperties(user, **user_properties):
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   483
  """(see updateUserProperties)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   484
  
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   485
  Like updateUserProperties(), but not run within a transaction. 
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   486
  """
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   487
  properties = user.properties()
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   488
  
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   489
  for prop in properties.values():
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   490
    if prop.name in user_properties:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   491
      if prop.name == 'former_ids':
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   492
        # former_ids cannot be overwritten directly
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   493
        continue
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   494
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   495
      value = user_properties[prop.name]
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   496
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   497
      if prop.name == 'id':
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   498
        old_id = user.id
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   499
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   500
        if value != old_id:
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   501
          user.former_ids.append(old_id)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   502
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   503
      prop.__set__(user, value)
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   504
        
Todd Larsen <tlarsen@google.com>
parents: 112
diff changeset
   505
  user.put()
262
52a42831d9d6 Factor out an isIdAvailable() function from EditForm.clean_id() in
Todd Larsen <tlarsen@google.com>
parents: 245
diff changeset
   506
  return user