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


Python Vote.insert方法代码示例

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


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

示例1: post_vote

# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import insert [as 别名]
def post_vote(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
    vote = request.params["vote"]
    mission_id = request.params["missionId"]
    mission = Mission.get(Mission.id == mission_id, Mission.room == room)
    Vote.insert(player=you, mission=mission, vote=vote).execute()
    votes = Vote.select(Vote, Player).join(Player).where(Vote.mission == mission).execute()
    if votes.count == room.size:
        upvotes = sum(1 for v in votes if v.vote == "yes")
        agreed = True if (upvotes * 2 > votes.count) else False
        votes_message_data = {
            "votes": [
                {"player": {"id": vote.player.id, "name": vote.player.name}, "vote": vote.vote} for vote in votes
            ],
            "agreed": agreed,
        }
        messages = [Msg("votes", votes_message_data)]
        if agreed:
            room.phase = Room.PHASE_MISSION
            room.save()
        else:
            room.phase = Room.PHASE_TEAM_BUILD
            leader = next_leader(room)
            leader_message_data = {"leader": {"id": leader.id, "name": leader.name}}
            messages.append(Msg("leader", leader_message_data))
        post_message(messages, room=room)
开发者ID:warownia1,项目名称:TheResistance,代码行数:30,代码来源:views.py


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