当前位置: 首页>>代码示例>>Python>>正文


Python Player.create_all方法代码示例

本文整理汇总了Python中models.Player.create_all方法的典型用法代码示例。如果您正苦于以下问题:Python Player.create_all方法的具体用法?Python Player.create_all怎么用?Python Player.create_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.create_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_game

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create_all [as 别名]
def create_game(user, content):
    """Creates a pending game."""
    name        = content['name']
    max_points  = max(content['max_points'], 5)
    max_players = content['max_players']
    random      = content['random']
    emails      = content['emails']

    if len(emails) < 3:
        return jsonify(message='You need to invite more people!'), 418

    game = Game.create(
        user, name, max_points, min(max_players, len(emails) + 1), random
    )
    users   = User.get_all(emails) + [user]
    players = Player.create_all(users, game)

    player = next(
        (player for player in players if player.user == user),
        None
    )
    player.set_status_joined()

    notify(
        [u.device for u in users if u != user],
        'Politically Incorrect',
        'You\'ve been invited to a game: "{}"!'.format(name)
    )

    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise

    return jsonify(**{
        'id'         : game.id,
        '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,
                'status': p.status
            }
            for p in game.players
        ]
    })
开发者ID:25cf,项目名称:politically-incorrect,代码行数:52,代码来源:game.py

示例2: invite

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import create_all [as 别名]
def invite(id, user, content):
    """Invites a list of users."""
    game = Game.get(id)

    if not (user == game.host and game.status == Game.PENDING):
        return jsonify(message='I can\'t let you do that, Dave.'), 418

    emails  = content['emails']
    users   = User.get_all(emails)
    players = Player.create_all(users, game)
    game.invite_all(players)

    try:
        db.session.commit()
    except:
        db.session.rollback()
        raise

    return jsonify()
开发者ID:25cf,项目名称:politically-incorrect,代码行数:21,代码来源:game.py


注:本文中的models.Player.create_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。