Exemple #1
0
    def get_user_games(self, request):
        """Returns games for a specific user."""
        user = User.query(User.user_name == request.user_name).get()

        if user:
            if user.password != request.password:
                raise endpoints.UnauthorizedException(
                            'Invalid password!')

            user_plays = Player.query(Player.user == user.key)

            if user_plays:
                games = []
                for play in user_plays:
                    game = play.game.get()
                    if not game.game_over and not game.cancelled:
                        game_number = len(games)
                        games.append(
                            game.to_form('Game number %d.' % (game_number)))
                if len(games) != 0:
                    forms = GameForms()
                    forms.games = games
                    return forms
                else:
                    raise endpoints.NotFoundException(
                        'No active games found.')
            else:
                raise endpoints.NotFoundException('No games found.')
        else:
            raise endpoints.NotFoundException('User not found.')
Exemple #2
0
    def get_user_games(self, request):
        """Return all of a User's active games."""
        user = User.query(User.name == request.user_name).get()
        games = Game.query(Game.game_over == False, Game.user == user.key)

        items = [game.to_form_raw() for game in games]
        return GameForms(items=[game.to_form_raw() for game in games])
Exemple #3
0
 def get_user_games(self, request):
     """Returns all of an individual User's games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(Game.user == user.key, Game.game_over == False)
     return GameForms(games=[game.to_form("") for game in games])
 def get_user_games(self, request):
     """Return all games played by a user"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A user with that name does not exist!')
     games = Game.query(Game.user == user.key)
     return GameForms(items=[game.to_form() for game in games])
Exemple #5
0
 def get_user_games(self, request):
     """Returns all of an individual User's games, including ongoing and completed games."""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(Game.user == user.key)
     return GameForms(items=[game.to_form("") for game in games])
Exemple #6
0
 def get_user_game(self,request):
     """Return active games for specified user"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
                 'A User with that name does not exist!')
     games = Game.query(Game.user == user.key)
     active_games = games.filter(Game.game_over == False)
     return GameForms(items = [game.to_form("Time to make a move!") for game in active_games])
Exemple #7
0
 def get_user_games(self, request):
     """Return all avtive games under one specific user"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(Game.user == user.key).filter(
         Game.game_over == False)
     return GameForms(items=[game.to_form('') for game in games])
Exemple #8
0
 def get_user_games(self, request):
     """Return a User's active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.BadRequestException('User not found!')
     games = Game.query(ndb.OR(Game.player1 == user.key,
                        Game.player2 == user.key)).\
                        filter(Game.game_over == False)
     return GameForms(items=[game.to_form("User games retrieved") for game in games])
Exemple #9
0
 def get_user_games(self, request):
     """Returns all active games for a user"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A user with that name does not exist')
     games = Game.query(Game.user == user.key, Game.game_over == False)
     print str(games)
     return GameForms(items=[game.to_form() for game in games])
Exemple #10
0
 def get_user_games(self, request):
     """Returns games user is a part of"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(Game.user == user.key).fetch()
     items = [game.to_form('string') for game in games]
     return GameForms(games=items)
Exemple #11
0
    def get_player_games(self, request):
        """Return all games from Player"""
        player = Player.get_player_by_name(request.name)
        if not player:
            raise endpoints.NotFoundException('Player does not exist')
        games = Game.query(ndb.OR(Game.playerOne == player.key,
                                  Game.playerTwo == player.key)).filter(Game.gameOver == False)

        return GameForms(items=[game.copy_game_to_form() for game in games])
Exemple #12
0
 def get_user_games(self, request):
     """Returns all of a User's active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     # print "test", user
     # print user.email
     gamez = RPS.query(ancestor=ndb.Key(User, user.email))
     return GameForms(items=[gaym.to_form("test") for gaym in gamez])
 def get_user_games(self, request):
     """Returns all of an individual User's active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(
         ndb.AND(ndb.OR(Game.player1 == user.key, Game.player2 == user.key),
                 Game.game_over == False))
     return GameForms(items=[game.to_form('') for game in games])
Exemple #14
0
 def get_user_games(self, request):
     """Return all User's active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.BadRequestException('User not found!')
     games = Game.query(Game.user == user.key).\
         filter(Game.game_over is False)
     return GameForms(items=[
         game.to_form('Games for user: ' + str(User.name)) for game in games
     ])
 def get_user_games(self, request):
     """Returns all of the users active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException('User name is required')
     games = Game.query(
         ndb.AND(
             ndb.OR(Game.player_one == user.key,
                    Game.player_two == user.key), Game.game_over == False))
     return GameForms(items=[game.to_form() for game in games])
Exemple #16
0
    def get_user_games(self, request):
        """Returns all of an individual User's ACTIVE games"""
        user = User.query(User.name == request.name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')

        game_keys = [ndb.Key(urlsafe=wsck) for wsck in user.activeGameKeys]
        games = ndb.get_multi(game_keys)
        return GameForms(items=[game.to_form() for game in games])
 def get_user_games(self, request):
     """Returns all of a user's active games"""
     user = self._getInfoFromUser()
     if not user:
         raise endpoints.NotFoundException('User is not signed in!')
     user_games = Game.query(
         ndb.AND(
             ndb.OR(Game.user_one == user.key, Game.user_two == user.key),
             Game.game_over == False))
     return GameForms(items=[game.to_form("") for game in user_games])
Exemple #18
0
 def get_user_games(self, request):
     """Return all active (unfinished) games for specified user."""
     user = User.query(User.username == request.username).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     query = Game.query()\
         .filter(Game.game_over == False)\
         .filter(Game.user == user.key)
     return GameForms(games=[game.to_form() for game in query])
    def get_user_games(self, request):
        """Returns all of an individual User's active games"""
        user = User.query(User.screen_name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')
        games = Game.query(ancestor=user.key)
        games = games.filter(Game.game_over == False)
        games = games.filter(Game.game_cancelled != True)

        return GameForms(games=[game.to_form('') for game in games])
Exemple #20
0
    def get_user_games(self, request):
        """ Gets all of a user's active games"""
        # TODO: make all games descendants of a user

        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                    'A User with that name does not exist!')
        games = Game.query(Game.user == user.key, Game.game_over == False)  # noqa

        return GameForms(items=[game.to_form() for game in games])
Exemple #21
0
 def get_user_games(self, request):
     """Returns all of an individual User's scores"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
                 'A User with that name does not exist!')
     games = Game.query(Game.user == user.key,
                        Game.cancelled == False,
                        Game.game_over == False).fetch()        
     return GameForms(items=[game.to_form('Returning game for user:' +
                                          user.name) for game in games])
 def get_user_games(self, request):
     """
     Returns all the Users active games
     """
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException("User %s dosn't exist" %
                                           request.user_name)
     #  we only care about the game that are not complete
     games = Game.query(Game.user == user.key).filter(
         Game.game_over == False)
     return GameForms(items=[game.to_form('') for game in games])
Exemple #23
0
    def get_user_games(self, request):
        """Return the current game state."""
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')
        find_user = ndb.OR(Game.user1 == user.key, Game.user2 == user.key)
        user_games = Game.query(find_user, Game.game_over == False,
                                Game.cancelled == False)

        return GameForms(
            items=[user_game.to_form('') for user_game in user_games])
Exemple #24
0
 def get_user_games(self, request):
     """Get user active games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException('User not found')
     ancestor_key = ndb.Key(User, user.name)
     # Get user games that are still active
     return GameForms(items=[
         game.to_form('Game online')
         for game in Game.query(ancestor=ancestor_key).filter(
             Game.game_over == False, Game.canceled == False)
     ])
Exemple #25
0
    def get_user_games(self, request):
        '''Get all active games a user is playing'''
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                '''A user with that name does not exist''')

        # attempt to match user and user key
        qry1 = Game.query(Game.user == user.key)
        games = qry1.filter(Game.game_over == False)
        return GameForms(
            items=[game.to_form("Active Game!") for game in games])
Exemple #26
0
    def get_user_games(self, request):
        """Returns all of a User's active games"""
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')

        games = Game.query(Game.user == user.key, Game.game_over == False,
                           Game.cancelled != True)

        return GameForms(
            items=[game.to_form('Marks: %s' % game.marks) for game in games])
    def game_history(self, request):

        game = get_by_urlsafe(request.urlsafe_game_key, Game)
        if not game:
            raise endpoints.NotFoundException('Game not found!')

        game_history = GameHistory.query(ancestor=game.key).get()

        items = []
        for index, item in enumerate(game_history.history):
            items.append(item.to_form(game_history.messages[index]))

        return GameForms(items=items)
Exemple #28
0
    def get_user_games(self, request):
        """Get an user's active games"""
        user = User.query(User.name == request.user_name).get()

        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')

        # Get only games that are active and belong to this user
        games = Game.query(Game.user == user.key)
        games = games.filter(Game.game_over == False)

        return GameForms(games=[game.to_form("Good luck!") for game in games])
Exemple #29
0
 def get_user_games(self, request):
     """Return all Player's active games"""
     player = Player.query(Player.name == request.user_name).get()
     if not player:
         raise endpoints.BadRequestException('User not found!')
     games = Game.query(
         ndb.AND(
             Game.finished_status == False,
             ndb.OR(Game.player1 == player.key,
                    Game.player2 == player.key)))
     # Ancestor query hence the key
     return GameForms(
         items=[game.to_form_without_message() for game in games])
Exemple #30
0
 def get_user_games(self, request):
     """Get an individual user's current games"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     games = Game.query(Game.user == user.key)
     games = games.filter(Game.game_over == False)
     if games.count() > 0:
         return GameForms(items=[game.to_form("{}'s active games.".format(
             request.user_name)) for game in games])
     else:
         raise endpoints.NotFoundException('This user has no active games!')
Exemple #31
0
    def get_user_games(self, request):
        """Return all active games created by a user"""
        user = User.query(User.user_name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException("The User does not exist")

        games = Game.query(ancestor=user.key).filter(
            Game.game_over==False).fetch()

        if not games:
            raise endpoints.NotFoundException(
                "The User does not have any Game")

        return GameForms(items=[game.to_form("Make a move") for game in games])