Пример #1
0
 def submit(self, request):
     try:
         game_memberships = GameMember.filterByUser(request.user.pk)
         games = [Game.getByID(mem.game_id) for mem in game_memberships]
     except CassaNotFoundException:
         raise GameNotFound()
     return GameSerializer(games, many=True).data
Пример #2
0
    def submit(self, request):
        try:
            game = Game.getByID(self.cleaned_data['game_id'])
            if game.current_round_id:
                raise GameAlreadyStarted()
        except CassaNotFoundException:
            raise GameNotFound()
        
        if not GamePermissions.has_object_permission(request, game):
            raise PermissionDenied()
        
        # select randomly from the game members
        game_members = GameMember.filterByGame(game.game_id)
        selector = random.choice(game_members)
        
        now = datetime.datetime.now()
        
        round = Round(selector_id=selector.user_id, phrase_card_id=PhraseCard.getRandom(self.cleaned_data['deck_id']).phrase_card_id,
            game_id=game.game_id, date_created=now, last_modified=now)
        
        round.save()
        
        game.deck = self.cleaned_data['deck_id']
        game.current_round_id = round.round_id
        game.save()

        return RoundSerializer(round).data
Пример #3
0
 def submit(self, request):
     try:
         game = Game.getByID(self.cleaned_data['game_id'])
         if not GamePermissions.has_object_permission(request, game):
             raise BadRequestException()
     except CassaNotFoundException:
         raise GameNotFound()
     return GameSerializer(game).data
Пример #4
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
Пример #5
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
Пример #6
0
 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
Пример #7
0
 def submit(self, request):
     '''
         Submits this form to create the given game.
     '''
     game_members = self.cleaned_data['game_members']
     del self.cleaned_data['game_members']
     self.cleaned_data['leader_id'] = UUID(request.user.pk)
     game = Game.fromMap(self.cleaned_data)
     game.save()
     
     members_added = {}
     
     for mem in game_members:
         try:
             mem = str(UUID(mem))
             UserClient(request.auth).get(mem)
             # user exists so let's add him/her
             now = datetime.datetime.now()
             member = GameMember(game_member_id=str(uuid.uuid1()), game_id=UUID(game.game_id), user_id=UUID(mem), status=1, date_created=now, last_modified=now)
             member.save()
             members_added[member.game_member_id] = now
         except ValueError, UserClientError:
             continue
Пример #8
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