def post(self): result = {"error": None, "data": {}} parser = reqparse.RequestParser() parser.add_argument("descriptors", type=list, default=[], location="json") args = parser.parse_args() result["data"]["search"] = {} data = {} for service in args["descriptors"]: if service not in choices: return abort("general", "service-not-found") data[service] = [] descriptors = DescriptorService.list(service) for descriptor in descriptors: data[service].append(descriptor.dict()) result["data"]["search"]["descriptors"] = data result["data"]["search"]["years"] = AnimeService.years() return result
def post(self): result = {"error": None, "data": {}} parser = reqparse.RequestParser() parser.add_argument("service", type=str, required=True, choices=choices) parser.add_argument("slug", type=str, required=True) parser.add_argument("params", type=dict, default={}) args = parser.parse_args() descriptor = DescriptorService.get_by_slug(args["service"], args["slug"]) if descriptor is None: return abort(args["service"], "not-found") keys = ["name", "slug", "description"] update = utils.filter_dict(args["params"], keys) update_document(descriptor, update) try: descriptor.save() except Exception: return abort("general", "empty-required") result["data"] = descriptor.dict() return result
def franchise(slug): franchise = DescriptorService.get_by_slug("franchise", slug) if not franchise: response = abort("franchise", "not-found") flask_abort(response) return franchise
def new_descriptor(): result = {"error": None, "data": {}} parser = RequestParser() parser.argument("service", type=helpers.descriptor_service, required=True) parser.argument("name", type=str, required=True) parser.argument("slug", type=str, required=True) parser.argument("description", type=str) args = parser.parse() check = DescriptorService.get_by_slug(args["service"], args["slug"]) if check: return abort(args["service"], "slug-exists") descriptor = DescriptorService.create( args["service"], args["name"], args["slug"], args["description"]) result["data"] = descriptor.dict() return result
def post(self): result = {"error": None, "data": {}} parser = reqparse.RequestParser() parser.add_argument("service", type=str, required=True, choices=choices) parser.add_argument("description", type=str, default=None) parser.add_argument("name", type=str, required=True) parser.add_argument("slug", type=str, required=True) args = parser.parse_args() check = DescriptorService.get_by_slug(args["service"], args["slug"]) if check is not None: return abort(args["service"], "slug-exists") descriptor = DescriptorService.create(args["service"], args["name"], args["slug"], args["description"]) result["data"] = descriptor.dict() return result
def post(self): result = {"error": None, "data": {}} parser = reqparse.RequestParser() parser.add_argument("franchises", type=list, default=[], location="json") parser.add_argument("subtitles", type=list, default=[], location="json") parser.add_argument("voiceover", type=list, default=[], location="json") parser.add_argument("aliases", type=list, default=[], location="json") parser.add_argument("genres", type=list, default=[], location="json") parser.add_argument("description", type=str, required=True) parser.add_argument("category", type=str, required=True) parser.add_argument("title", type=dict, required=True) parser.add_argument("team", type=str, required=True) parser.add_argument("year", type=int, required=True) parser.add_argument("state", type=str, default=None) args = parser.parse_args() title_parser = reqparse.RequestParser() title_parser.add_argument("jp", type=str, default=None, location=("title", )) title_parser.add_argument("ua", type=str, location=("title", )) title_args = title_parser.parse_args(req=args) for alias in args["aliases"]: if type(alias) is not str: return abort("general", "alias-invalid-type") team = TeamService.get_by_slug(args["team"]) if team is None: return abort("team", "not-found") if request.account not in team.members: return abort("account", "not-team-member") if not PermissionService.check(request.account, "global", "publishing"): return abort("account", "permission") category = DescriptorService.get_by_slug("category", args["category"]) if category is None: return abort("category", "not-found") state = DescriptorService.get_by_slug("state", args["state"]) if state is None: return abort("state", "not-found") if args["description"] is None: return abort("general", "missing-field") genres = [] 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") franchises = [] 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") subtitles = [] for username in args["subtitles"]: subtitles_account = UserService.get_by_username(username) if subtitles_account is not None: subtitles.append(subtitles_account) else: return abort("account", "not-found") voiceover = [] for username in args["voiceover"]: voiceover_account = UserService.get_by_username(username) if voiceover_account is not None: voiceover.append(voiceover_account) else: return abort("account", "not-found") title = AnimeService.get_title(title_args["ua"], title_args["jp"]) search = utils.create_search(title_args["ua"], title_args["jp"], args["aliases"]) slug = utils.create_slug(title_args["ua"]) anime = AnimeService.create(title, slug, args["description"], args["year"], search, category, state, genres, franchises, [team], subtitles, voiceover, args["aliases"]) result["data"] = anime.dict() return result
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