Ejemplo n.º 1
0
def get_game_by_id(game_id=None):
    """Get the game from db with the id provided
        Args:
            :param _id: The id of the game to search in db
                :type: Game
        Returns:
            Game: The game if it is already stored, None in other case
    """
    if game_id is None:
        return None
    return Game.get(game_id)
Ejemplo n.º 2
0
def join_game(game_id=None, user=None):
    """

    :param game_id: idof the game that user joins
    :param user: user what joins the game
    """

    if user is not None and game_id is not None:
        game = Game.get(game_id)
        Participant.get_or_insert(key_name=user.email + "_" + game_id,
                                  game=game,
                                  user=user)
Ejemplo n.º 3
0
def delete_game(game_id=None, user=None):
    """Delete the game from db

        Args:
            :param game_id: The game id which is going to be deleted from db
                :type: Game
    """
    if user is not None and game_id is not None:
        game = Game.get(game_id)
        if game.owner.key() == user.key() or user.role == "admin":
            for treasure in game.treasures:
                db.delete(treasure.images)
                db.delete(treasure)
            db.delete(game)