def submit(self, request): try: game = Game.getByID(self.cleaned_data['game_id']) except CassaNotFoundException: raise GameNotFound() if not GamePermissions.has_object_permission(request, game): raise PermissionDenied() if not game.current_round_id: raise NoCurrentRound() try: round = Round.getByID(game.current_round_id) except CassaNotFoundException: raise RoundNotFound() if request.user.pk != str(round.selector_id): raise NotTheSelector() try: nomination = Nomination.getByID(self.cleaned_data['selection_id']) except CassaNotFoundException: raise InvalidNominationCard() round.selection_id = self.cleaned_data['selection_id'] round.save() game_members = GameMember.filterByGame(game.game_id) # finds the game state that should be updated member = None for m in game_members: if str(m.user_id) == str(nomination.nominator_id): member = m break member.score += 10 member.save() # creates a new round, saves it and the game now = datetime.datetime.now() selector = random.choice(game_members) new_round = Round(selector_id=selector.user_id, phrase_card_id=PhraseCard.getRandom(game.deck).phrase_card_id, game_id=game.game_id, date_created=now, last_modified=now) new_round.save() game.current_round_id = new_round.round_id game.save() return RoundSerializer(new_round).data
def submit(self, request): game_id = self.cleaned_data['game_id'] try: game = Game.getByID(game_id) except CassaNotFoundException: raise GameNotFound() if not GamePermissions.has_object_permission(request, game): raise PermissionDenied() try: if not game.current_round_id: raise NoCurrentRound() round = Round.getByID(game.current_round_id) except CassaNotFoundException: raise NoCurrentRound() return RoundSerializer(round).data