本文整理汇总了Python中models.Match.query方法的典型用法代码示例。如果您正苦于以下问题:Python Match.query方法的具体用法?Python Match.query怎么用?Python Match.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import query [as 别名]
def get(self):
"""Send a reminder email to each User with active Matches.
Called every hour using a cron job"""
app_id = app_identity.get_application_id()
users = User.query(User.email != None)
for user in users:
matches = Match.query(ndb.AND(Match.is_active == True,
ndb.OR(
Match.player_1_name == user.name,
Match.player_2_name == user.name)
)).fetch()
if matches:
subject = 'Unfinished match reminder!'
body = 'Hello {}, \n\nThe following matches are still in ' \
'progress:\n'.format(user.name)
html = 'Hello {}, <br><br>The following matches are still in ' \
'progress:<br>'.format(user.name)
for match in matches:
body += '{} vs {}\n'.format(match.player_1_name,
match.player_2_name)
html += '{} vs {}<br>'.format(match.player_1_name,
match.player_2_name)
body += 'https://{}.appspot.com">Continue playing'\
.format(app_id)
html += '<a href="https://{}.appspot.com">Continue playing' \
'</a>'.format(app_id)
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
user.email, subject, body, html=html)
示例2: get
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import query [as 别名]
def get(self):
""" Send a reminder to players who have unfinished matches """
app_id = app_identity.get_application_id()
matches = Match.query(Match.match_over == False)
players = list()
for match in matches:
logger.debug(match)
players.append(match.player)
# Remove duplicates in list by list-set-list conversion
players = list(set(players))
# Get players from datastore
players = ndb.get_multi(players)
# Create message and send to each player
for player in players:
subject = 'This is a reminder'
body = """Hello %s,
you have unfinished
quizzles business!""" % player.user_name
mail.send_mail('[email protected]{}.appspotmail.com'.format(app_id),
player.email_address,
subject,
body)
示例3: get
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import query [as 别名]
def get(self):
for match in Match.query(Match.winning_faction == None, Match.date <= datetime.datetime.now()):
match.play_match()
for match_player in MatchPlayer.query(MatchPlayer.match == match.key):
player = match_player.player.get()
player.doing = None
player.put()
websocket_notify_player("Match_Finished", player.key, None, match.get_data("full"))
websocket_notify_player("Player_StatsChanged", player.key, "player", {'stats': player.get_stats_data()})
示例4: get_user_matches
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import query [as 别名]
def get_user_matches(self, request):
"""Get all active Matches for a User"""
matches = Match.query(ndb.AND(Match.is_active == True,
ndb.OR(
Match.player_1_name ==
request.player_name,
Match.player_2_name ==
request.player_name))).fetch()
return StringMessages(message=[match.key.urlsafe()
for match in matches])
示例5: get_user_matches
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import query [as 别名]
def get_user_matches(self, request):
""" Lists a player's matches.
This functions delivers a list of matches by a specific player. It
also allows pagination.
(NB: Change QUERY_LIMIT to increase/decrease results per page)
Returns:
MatchForms -- a list of matches in MatchForm representation
"""
# Get limit and offset based on requested page
limit, offset = get_limit_offset(request.page)
# Get the specified player's matches
player = get_player(request.user_name)
matches = Match.query(ancestor=player.key).fetch(offset=offset,
limit=limit)
matches = [match.to_form() for match in matches]
# Return matches
return MatchForms(matches=matches)