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/')
评论列表
文章目录