本文整理汇总了Python中models.Vote.select方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.select方法的具体用法?Python Vote.select怎么用?Python Vote.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import select [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)
示例2: votes_json
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import select [as 别名]
def votes_json(track):
votes = Vote.select().where(Vote.track_uri == track.uri)
for vote in votes:
yield {
'user': vote.user.name,
'uid': vote.user.uid,
'picture': vote.user.picture,
'time': vote.timestamp.isoformat()
}