本文整理汇总了Python中models.Match.make_unique_gamename方法的典型用法代码示例。如果您正苦于以下问题:Python Match.make_unique_gamename方法的具体用法?Python Match.make_unique_gamename怎么用?Python Match.make_unique_gamename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.make_unique_gamename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newgame
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import make_unique_gamename [as 别名]
def newgame():
"""Create new game from request. Commit new game to db, save to fold.
Form Parameters:
name: new game name
player{1,2,..}: players to add (e.g. /newgame?player1=joe&player2=sally)
add_gems: gems to add to default (e.g. rgbbb)
If game exists, redirect to game with that name.
"""
# PARSE FORM INPUTS
args = request.form or request.args
suggested_name = args.get('game') or 'default' #TODO make default name
name = Match.make_unique_gamename(suggested_name)
players = [player for k, player in args.items() if 'player' in k and player]
add_gems = args.get('add_gems') or ""
# MAKE SURE PLAYERS EXIST
users = []
for pname in players:
u = User.query.filter_by(nickname=pname).first()
if not u: return "invalid player name, %s"%pname #TODO better error handling
else: users.append(u)
# Get ongoing match names
active_matches = [m.name for m in Match.query.filter_by(is_active=True)]
if name not in active_matches:
print players
print type(players)
# create game
args = pickle.load(open('game_args.pickle', 'rb'))
G = MutableGame(*args)
G.start(players, add_gems)
# create db entry
m = Match(name=name, is_active=True, creator=g.user.id, game=G, summary=str(G))
m.players.extend(users)
db.session.add(m)
db.session.commit()
# save initial copy of game and add to game dict
#G.save(savedir + '/' + name)
return redirect('/game/%s'%name)