Exemplo n.º 1
0
 def submit(self, request):
     game = Game.getByID(self.cleaned_data['game_id'])
     if not game.current_round_id:
         raise NoCurrentRound()
     
     if not GamePermissions.has_object_permission(request, game):
         raise PermissionDenied()
     
     nominations = Nomination.filterByRound(game.current_round_id)
     return NominationSerializer(nominations, many=True).data
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 def submit(self, request):
     game = Game.getByID(self.cleaned_data['game_id'])
     if not game.current_round_id:
         raise NoCurrentRound()
     
     if not GamePermissions.has_object_permission(request, game):
         raise PermissionDenied()
     
     nominations = Nomination.filterByRound(game.current_round_id)
     users = set([str(n.nominator_id) for n in nominations])
     if request.user.pk in users:
         raise AlreadyNominated()
     
     now = datetime.datetime.now()
     try:
         NominationCard.getByID(self.cleaned_data['nomination_card_id'])
     except CassaNotFoundException:
         raise InvalidNominationCard()
     
     nomination = Nomination(round_id=game.current_round_id, nominator_id=request.user.pk,
             nomination_card_id=self.cleaned_data['nomination_card_id'], date_created=now, last_modified=now)
     nomination.save()
     
     return NominationSerializer(nomination).data