當前位置: 首頁>>代碼示例>>Python>>正文


Python UserModel.query方法代碼示例

本文整理匯總了Python中models.user.UserModel.query方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.query方法的具體用法?Python UserModel.query怎麽用?Python UserModel.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.user.UserModel的用法示例。


在下文中一共展示了UserModel.query方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: insert_user

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import query [as 別名]
 def insert_user(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         raise endpoints.UnauthorizedException('Authorization required')
     
     logging.info('user '+str(current_user))
     user_id = (current_user.user_id() if current_user is not None and current_user.user_id() is not None
              else 'Anonymous')
     email = (current_user.email() if current_user is not None
              else '[email protected]')
     query = UserModel.query(UserModel.email == email).fetch()
     logging.info('LEN '+str(len(query)))
     userDb = None
     if len(query) > 0:
         userDb = query[0]
         logging.info('DB '+str(userDb))
     else:
         userDb = UserModel(user_id=user_id , email=email)
         userDb.key = ndb.Key('UserModel',email)
         userDb.put()
     
     key = userDb.key.urlsafe()
     #key = userDb.key.id()
     user = User(user_id=userDb.user_id,
                 email=userDb.email,
                 key=str(key))
     
     return user
開發者ID:jmn8718,項目名稱:gae-endpoint-app,代碼行數:30,代碼來源:backend_api.py

示例2: list_users

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import query [as 別名]
 def list_users(self, request):
     usersList = UserModel.query().fetch()
     items = []
     for userItem in usersList:
         items.append(User(user_id=userItem.user_id,
                           email=userItem.email,
                           key=str(userItem.key.id()),
                           strava_id=userItem.strava_id,
                           strava_token=userItem.strava_token))
     return UserCollection(data = items)
開發者ID:jmn8718,項目名稱:gae-endpoint-app,代碼行數:12,代碼來源:backend_api.py

示例3: add_user

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import query [as 別名]
def add_user(user):
    logging.info("user " + str(user))
    user_id = user.user_id() if user is not None and user.user_id() is not None else "Anonymous"
    email = user.email() if user is not None else "[email protected]"
    query = UserModel.query(UserModel.email == email).fetch()
    logging.info("LEN " + str(len(query)))
    userDb = None
    if len(query) > 0:
        userDb = query[0]
        logging.info("DB " + str(userDb))
    else:
        userDb = UserModel(user_id=user_id, email=email)
        userDb.key = ndb.Key("UserModel", email)
        userDb.put()
    return userDb
開發者ID:jmn8718,項目名稱:gae-endpoint-app,代碼行數:17,代碼來源:public.py


注:本文中的models.user.UserModel.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。