Exemple #1
0
    def post(self):
        result = {"error": None, "data": []}

        parser = reqparse.RequestParser()
        parser.add_argument("franchises",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("categories",
                            type=list,
                            default=[],
                            location="json")
        parser.add_argument("states", type=list, default=[], location="json")
        parser.add_argument("genres", type=list, default=[], location="json")
        parser.add_argument("teams", type=list, default=[], location="json")
        parser.add_argument("query", type=str, default="")
        parser.add_argument("page", type=int, default=0)
        parser.add_argument("year", type=dict)
        args = parser.parse_args()

        year_parser = reqparse.RequestParser()
        year_parser.add_argument("min",
                                 type=int,
                                 default=None,
                                 location=("year", ))
        year_parser.add_argument("max",
                                 type=int,
                                 default=None,
                                 location=("year", ))
        year_args = year_parser.parse_args(req=args)

        query = utils.search_query(args["query"])
        categories = []
        franchises = []
        genres = []
        states = []
        teams = []

        for slug in args["categories"]:
            category = DescriptorService.get_by_slug("category", slug)
            if category is not None:
                categories.append(category)
            else:
                return abort("category", "not-found")

        for slug in args["genres"]:
            genre = DescriptorService.get_by_slug("genre", slug)
            if genre is not None:
                genres.append(genre)
            else:
                return abort("genre", "not-found")

        for slug in args["franchises"]:
            franchise = DescriptorService.get_by_slug("franchise", slug)
            if franchise is not None:
                franchises.append(franchise)
            else:
                return abort("franchise", "not-found")

        for slug in args["states"]:
            state = DescriptorService.get_by_slug("state", slug)
            if state is not None:
                genres.append(state)
            else:
                return abort("state", "not-found")

        for slug in args["teams"]:
            team = TeamService.get_by_slug(slug)
            if team is not None:
                teams.append(team)
            else:
                return abort("team", "not-found")

        anime = AnimeService.search(query, year_args, categories, genres,
                                    franchises, states, teams, args["page"])

        for anime in anime:
            result["data"].append(anime.dict())

        return result
Exemple #2
0
def list_anime():
    result = {"error": None, "data": []}

    parser = RequestParser()
    parser.argument("franchises", type=list, default=[], location="json")
    parser.argument("categories", type=list, default=[], location="json")
    parser.argument("ordering", type=list, default=[], location="json")
    parser.argument("states", type=list, default=[], location="json")
    parser.argument("genres", type=list, default=[], location="json")
    parser.argument("teams", type=list, default=[], location="json")
    parser.argument("query", type=str, default="")
    parser.argument("page", type=int, default=0)
    parser.argument("year", type=dict)
    args = parser.parse()

    year_parser = RequestParser()
    year_parser.argument("min", type=int, location="year")
    year_parser.argument("max", type=int, location="year")
    year_args = year_parser.parse(req=args)

    query = utils.search_query(args["query"])
    categories = []
    franchises = []
    ordering = []
    genres = []
    states = []
    teams = []

    for slug in args["categories"]:
        category = helpers.category(slug)
        categories.append(category)

    for slug in args["genres"]:
        genre = helpers.genre(slug)
        genres.append(genre)

    for slug in args["franchises"]:
        franchise = helpers.franchise(slug)
        franchises.append(franchise)

    for slug in args["states"]:
        state = helpers.state(slug)
        states.append(state)

    for slug in args["teams"]:
        team = helpers.team(slug)
        teams.append(team)

    for item in args["ordering"]:
        check = item
        if item[0] in ["+", "-"]:
            check = item[1:]

        if check in ("rating"):
            ordering.append(check)

    anime = AnimeService.search(query,
                                year_args,
                                categories,
                                genres,
                                franchises,
                                states,
                                teams,
                                ordering,
                                False,
                                args["page"],
                                account=request.account)

    for item in anime:
        result["data"].append(item.dict())

    return result