本文整理汇总了Python中models.Player.get方法的典型用法代码示例。如果您正苦于以下问题:Python Player.get方法的具体用法?Python Player.get怎么用?Python Player.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Player
的用法示例。
在下文中一共展示了Player.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_player
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def get_player(nick_name='', steam_id=''):
"""
gets player by given params.
If player changed nickname - replaces old one in db
If no such player - creates new
:param nick_name:
:param steam_id:
:param may_be_new:
:return:Player object
"""
print nick_name, steam_id
if nick_name and not steam_id:
try: # FIXME: temporary crutch while checking old players steam_id is impossible (asker required)
return Player.get(nick_name=nick_name)
except:
player = Player.create(steam_id=0, nick_name=nick_name)
return player
elif steam_id and not nick_name:
return Player.get(steam_id=steam_id)
elif steam_id and nick_name:
try:
player = Player.get(steam_id=steam_id)
except:
player = Player.create(steam_id=steam_id, nick_name=nick_name)
if nick_name != player.nick_name:
player.nick_name = nick_name # TODO: test for it
player.save()
return player
示例2: set_answer
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def set_answer(puzzle_name, player_id, question, content_type, content):
player = Player.get(Player.id == player_id)
puzzle, _ = Puzzle.get_or_create(name=puzzle_name)
try:
answer = Answer.get(
(Answer.puzzle == puzzle) & (Answer.player == player))
except Answer.DoesNotExist:
answer = Answer(puzzle=puzzle, player=player)
answer.question = question
if content_type == 'text':
answer.value = content
elif content_type == 'image':
filename = '%s_%s.jpg' % (puzzle.id, player.id)
path = '%s/images/%s' % (STATIC_DIR, filename)
with open(path, 'wb') as fp:
fp.write(content)
answer.value = 'image:' + filename
elif content_type == 'video':
filename = '%s_%s.mp4' % (puzzle.id, player.id)
path = '%s/videos/%s' % (STATIC_DIR, filename)
with open(path, 'wb') as fp:
fp.write(content)
answer.value = 'video:' + filename
answer.save()
示例3: accept_or_decline_game
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def accept_or_decline_game(id, action, user, content):
"""Join/invite/decline actions for games."""
game = Game.get(id)
player = Player.get(user, game)
started = False
if action == 'add':
player.set_status_joined()
joined = [p for p in game.players
if p.status == Player.JOINED]
if len(joined) == game.max_players:
notify(
[p.user.device for p in game.players if p.user.device and p != player],
'Politically Incorrect',
'The game "{}" has started!'.format(game.name)
)
game.start()
started = True
elif action == 'delete':
player.set_status_denied()
else:
return jsonify(), 404
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify(started=started)
示例4: who_am_i
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def who_am_i(player_id):
player = Player.get(Player.id == player_id)
anagram, description = WHO_AM_I_CLUES[player.order]
# Shuffle the letters.
anagram = list(anagram)
random.shuffle(anagram)
anagram = ''.join(anagram)
return '%s|%s' % (anagram, description)
示例5: register
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def register():
group_name = request.form['group'].strip()
player_name = request.form['player'].strip()
try:
# Perform case-insensitive search.
group = Group.get(fn.Lower(Group.name) == group_name.lower())
except:
group = Group.create(name=group_name)
try:
# Perform case-insensitive search.
player = Player.get(fn.lower(Player.name) == player_name.lower(), group=group)
except Player.DoesNotExist:
player = Player.create(
group=group, name=player_name, order=group.players.count())
return str(player.id)
示例6: game
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def game(room_code):
sessid = request.cookies.get("sessid")
you = Player.select(Player, Room).join(Room).where(Player.sessid == sessid, Room.code == room_code).get()
room = you.room
leader = Player.get(queue_position=room.leader_queue, room=room)
players = room.players.execute()
initial_data = {
"game": {"phase": room.phase, "round": room.round, "leader_queue": room.leader_queue},
"leader": {"id": leader.id, "name": leader.name},
"players": [{"id": plr.id, "name": plr.name, "queue_position": plr.queue_position} for plr in players],
"you": {"id": you.id, "name": you.name, "role": you.role},
}
context = {
"you": you,
"players": players,
"base_url": "/game/%s" % room_code,
"timestamp": time.time(),
"initial_data": json.dumps(initial_data),
}
if you.role == "spy":
spies = you.room.players.where(Player.role == "spy").execute()
context["spies"] = spies
return template("game", **context)
示例7: get
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def get(self):
# check for a cached version
#--------------------------------------------------------------------#
player_key = db.Key.from_path("Player", self.request.get("player_key_name"))
if self.emit(self.response.out, player_key):
return
# not cached or evicted from cache; regenerate
#--------------------------------------------------------------------#
player = Player.get(player_key)
if not player:
return
# player card
#--------------------------------------------------------------------#
banner_text_color = misc.get_contrasting_monochrome(player.team.color)
attr_table = Table(
columns = [
Column("MV", "Movement Allowance", attrgetter("mv")),
Column("ST", "Strength", attrgetter("st")),
Column("AG", "Agility", attrgetter("ag")),
Column("AV", "Armor Value", attrgetter("av")),
],
query = (player,),
cls = "attr",
)
injuries = []
for injury_key in player.injuries:
injury = db.get(injury_key)
if injury.key().name() == "Dead":
injuries.append("DEAD")
elif injury.permanent:
injuries.append("%s (%s)" % (injury.key().name(), injury.effect))
injuries = ", ".join(x for x in injuries)
skills = [k.name() for k in player.skills]
if player.level_up_pending:
skills.append("<i>Pending Level-Up</i>")
skills = ", ".join(skills)
# stat_table
#--------------------------------------------------------------------#
def get_left_header(tuple):
player, which = tuple
return which.capitalize()
def getter(stat):
def getter_closure(tuple):
player, which = tuple
try:
attr = getattr(player, "%s_%s" % (stat, which))
ave_attr = attr if player.played == 0 else attr / float(player.played)
return """<div class='tot_stat'>%d</div>
<div class='ave_stat'>%.1f</div>""" % (
attr, ave_attr)
except AttributeError:
return "-"
return getter_closure
stat_table = Table(
columns = [
Column("<span class='link' id='%s-show-averages-toggle'></span>" %
player.key(), "", get_left_header),
Column("TD", "Touchdowns", getter("tds")),
Column("P", "Pass completions", getter("passes")),
Column("YP", "Yards passing", getter("pyards")),
Column("R", "Pass receptions", getter("rec")),
Column("YR", "Yards rushing", getter("ryards")),
Column("K", "Kills", getter("kills")),
Column("C", "Casualties", getter("cas")),
Column("KO", "Knock outs", getter("ko")),
Column("S", "Stuns", getter("stun")),
Column("T", "Tackles", getter("tckl")),
Column("I", "Interceptions", getter("int")),
],
query = ((player, "for"), (player, "against")),
cls = "fancytable stats",
)
# match_table
#--------------------------------------------------------------------#
def name_getter(record):
opponent = record.team_record.opponent_record.team
return "<a rel='player_opponents' href='%s'>%s</a>" % (
opponent.get_box_href(), opponent.key().name())
def race_getter(record):
opponent = record.team_record.opponent_record.team
return "<img src='%s' />" % opponent.race.get_image_src(thumb=True)
def date_getter(record):
#.........这里部分代码省略.........
示例8: sign_language
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def sign_language(player_id):
player = Player.get(Player.id == player_id)
return SIGN_LANGUAGE_ASSIGNMENTS[player.order]
示例9: doodle
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def doodle(player_id):
player = Player.get(Player.id == player_id)
return DOODLE_ASSIGNMENTS[player.order]
示例10: icebreaker
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def icebreaker(player_id):
player = Player.get(Player.id == player_id)
return ICEBREAKER_QUESTIONS[player.order]
示例11: play
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def play(id, user, content):
"""
Handle main gameplay. If the requesting user
is the current judge, then expect an email
in the request body and interpret it as
the round winner chosen by the judge. Otherwise,
the request body should contain card ids in the
user's hand, which should be placed on the table.
request :=
POST ({
'cards': [int]
} | {
'email': str
})
"""
game = Game.get(id)
player = Player.get(user, game)
if game.status != Game.ONGOING:
return jsonify(message='This game isn\'t in-progress.'), 418
if user == game.judge.user:
email = content['email']
winner = next(
(player for player in game.players if player.user.email == email),
None
)
winner.add_points(1)
game.new_round(winner)
else:
if player.played:
return jsonify(), 418
cards = content['cards']
map = {card.id: card for card in player.hand}
cards = [map[card] for card in cards]
if len(cards) != game.black_card.answers:
return jsonify(message='Invalid play, mate.'), 418
player.play_cards(cards)
notify(
[p.user.device for p in game.players if p.user.device and p != player],
'Politically Incorrect',
'Something happened in "{}"!'.format(game.name)
)
for p in game.players:
p.seen = False
player.seen = True
try:
db.session.commit()
except:
db.session.rollback()
return jsonify()
示例12: get_game
# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import get [as 别名]
def get_game(id, user, content):
"""Returns a game in a format dependent on the game's status."""
game = Game.get(id)
player = Player.get(user, game)
if player not in [p for p in game.players if p.status != Player.REJECTED]:
return jsonify(
message='You can\'t see this game because you\'re not in it!'
), 418
if game.status == Game.PENDING:
return jsonify(**{
'id' : game.id,
'host' : {
'name' : game.host.name,
'email': game.host.email
},
'name' : game.name,
'max_points' : game.max_points,
'max_players': game.max_players,
'status' : game.status,
'players' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'status' : p.status,
'points' : 0
}
for p in game.players
]
})
elif game.status == Game.ONGOING:
if not player.seen:
player.seen = True
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify(**{
'id' : game.id,
'host' : {
'name' : game.host.name,
'email': game.host.email
},
'name' : game.name,
'max_points' : game.max_points,
'max_players': game.max_players,
'status' : game.status,
'black_card' : {
'id' : game.black_card.id,
'text' : game.black_card.text,
'answers': game.black_card.answers
},
'table' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'cards' : [
{
'id' : card.id,
'text': card.text
}
for card in p.get_played()
]
}
for p in game.players
if p.played and p != game.judge
],
'hand' : [
{
'id' : card.id,
'text': card.text
}
for card in player.hand
],
'judge' : {
'name' : game.judge.user.name,
'email': game.judge.user.email,
},
'players' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'status' : p.status,
'points' : p.score
}
for p in game.players
],
'previous' : game.previous_round
})
elif game.status == Game.ENDED:
return jsonify(**{
#.........这里部分代码省略.........