本文整理汇总了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
示例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)
示例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