本文整理汇总了Python中user.User.query方法的典型用法代码示例。如果您正苦于以下问题:Python User.query方法的具体用法?Python User.query怎么用?Python User.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.User
的用法示例。
在下文中一共展示了User.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get(self):
username = self.request.get("user")
password = self.request.get("password")
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
if not username or not password:
# some fields were missing in the request
self.response.write(json_error('invalid', ''))
else:
# check if username exists in db
query_user = User.query(User.username == username).fetch()
if query_user:
# check if password is correct
query = User.query(ndb.AND(User.username == username, User.pswd == password)).fetch()
if query:
# generate 64 char session cookie and send it back
cookie = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(64))
session = Session(cookie = cookie, user = username)
session.put()
self.response.write(login_response('ok', cookie))
else:
# password was incorrect
self.response.write(json_error('failure', 'password'))
else:
# user didn't exist
self.response.write(json_error('failure', 'user'))
示例2: get_high_scores
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get_high_scores(self, request):
"""
Returns a list of high scores in descending order.
Optional Parameter: number_of_results to limit the number of results returned.
"""
if request.number_of_results:
users = User.query().order(-User.high_score).fetch(request.number_of_results, offset=0)
else:
users = User.query().order(-User.high_score).fetch()
# users = sorted(users, key=lambda x: x.high_score, reverse=True)
return HighScoresForm(scores=[user.high_score for user in users])
示例3: _pre_delete_hook
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def _pre_delete_hook(cls, key):
q1 = User.query(ndb.OR(
User.held_coupons == key,
User.old_coupons == key
))
q2 = User.query(User.old_coupons == key)
for u in q1.iter():
try:
u.held_coupons.remove(key)
except ValueError:
u.old_coupons.remove(key)
finally:
u.put()
示例4: get
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get(self):
"""Send a reminder email to each User with an email who has
games in progress. Email body includes a count of active games and their
urlsafe keys
Called every hour using a cron job"""
app_id = app_identity.get_application_id()
users = User.query(User.email != None)
for user in users:
# Query for Users which have games in progress.
games = Game.query(Game.user == user.key).\
filter(Game.game_over == False)
if games.count() > 0:
subject = 'This is a reminder!'
body = 'Hello {}, you have {} games in progress. Their' \
' keys are: {}'.\
format(user.name, games.count()
,', '.join(game.key.urlsafe() for game in games))
logging.debug(body)
# This will send test emails, the arguments to send_mail are:
# from, to, subject, body
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
user.email,
subject,
body)
示例5: delete_user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def delete_user(self, request):
"""Deletes the User.
"""
print request.user_name
user = User.query(User.name == request.user_name).get()
if user:
user.key.delete()
return StringMessage(message='User {} deleted.'.format(request.user_name))
else:
raise endpoints.NotFoundException('User not found!')
示例6: create_game
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def create_game(self, request):
"""Creates new game."""
print 'new game requested for user ', request.user_name
user = User.query(User.name == request.user_name).get()
if not user:
raise endpoints.NotFoundException(
'A User with that name does not exist!')
game = Game.new_game(user.key)
return game.to_form()
示例7: create_user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def create_user(self, request):
"""Creates a User. Requires a unique username.
"""
if User.query(User.name == request.user_name).get():
raise endpoints.ConflictException(
'A User with that name already exists!')
user = User(name=request.user_name, email=request.email)
user.put()
# return StringMessage(message='User {} created!'.format(
# request.user_name))
return user.to_form()
示例8: get_user_games
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get_user_games(self, request):
"""Returns the user's active games."""
# Query for a user with this user name.
user = User.query(User.name == request.user_name).get()
if not user:
message = ('User {} not found!').format(request.user_name)
raise endpoints.NotFoundException(message)
# Query for all active games for this user.
games = Game.query(Game.user == user.key).filter(
Game.game_over == False)
return GameForms(games=[game.to_form() for game in games])
示例9: update_user
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def update_user(self, request):
"""Updates the User.
"""
user = User.query(User.name == request.user_name).get()
if user:
if request.email:
user.email = request.email
if request.high_score:
user.high_score = request.high_score
user.put()
return user.to_form()
else:
raise endpoints.NotFoundException('User not found!')
示例10: get
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get(self):
continue_url = self.request.get('continue')
if not continue_url:
continue_url = '/'
user = users.get_current_user()
if user:
existing_user = User.query(User.id == user.email()).fetch(1)
if not existing_user:
User(id=user.email(), user=user).put()
self.redirect(continue_url)
else:
data = { 'login_url': users.create_login_url('/login') }
html = utils.render_template('tl/login.html', data)
self.response.write(html)
示例11: get
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get(self):
username = self.request.get("user")
password = self.request.get("password")
email = self.request.get("email")
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
if not username or not password or not email:
# some fields were missing in the request
self.response.write(json_error('invalid', ''))
else:
query_user = User.query(User.username == username).fetch()
query_email = User.query(User.email == email).fetch()
if query_user:
# a user with this username exists already
self.response.write(json_error('failure', 'username'))
elif query_email:
# a user with this email exists already
self.response.write(json_error('failure', 'email'))
else:
# create a new user with the data recieved
user = User(username = username, pswd = password, email = email)
db_result = user.put()
self.response.write(register_response('ok'))
示例12: get
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get(self):
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
name = self.request.get('name')
if not name:
error = json_error('delete user', 'failure', 'name')
self.response.write(json.dumps(error))
else:
user = User.query(User.username == name).get()
if not user:
error = json_error('delete user', 'failure', 'no such user')
self.response.write(json.dumps(error))
else:
user.key.delete()
response = {'delete user': {'status': 'ok'}}
self.response.write(json.dumps(response))
示例13: get_holders
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get_holders(self, keys_only=False):
'''
Returns a list of users that are holding this coupon
'''
qry = User.query(User.held_coupons == self.key)
return [u for u in qry.iter()]
示例14: delete
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def delete(self):
users = User.query(User.held_coupons == self.key)
users.held_coupons.remove(self.key)
users.put()
self.key.delete()
示例15: get_users
# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import query [as 别名]
def get_users(self, request):
"""Returns all Users in the database."""
return UserForms(users=[user.to_form() for user in User.query()])