views.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:channels-obstruction 作者: codyparker 项目源码 文件源码
def dispatch(self, request, *args, **kwargs):
        # get the game by the id
        self.game = Game.get_by_id(kwargs['game_id'])
        user = get_user(request)
        # check to see if the game is open and available for this user
        # if this player is the creator, just return
        if self.game.creator == user or self.game.opponent == user:
            return super(GameView, self).dispatch(request, *args, **kwargs)

        # if there is no opponent and the game is not yet completed,
        # set the opponent as this user
        if not self.game.opponent and not self.game.completed:
            self.game.opponent = user
            self.game.save()
            return super(GameView, self).dispatch(request, *args, **kwargs)
        else:
            messages.add_message(request, messages.ERROR, 'Sorry, the selected game is not available.')
            return redirect('/lobby/')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号