Beispiel #1
0
    async def post(self, request: Request) -> _TemplateResponse:
        data = await request.form()

        fansub_id = request.path_params["id"]
        name = data.get("name", "")

        errors = []

        if not name:
            errors.append("The field name is mandatory.")

        try:
            Fansub.get(id=fansub_id, name=name)
            errors.append("A fansub with this name already exists.")
        except Fansub.DoesNotExist:
            pass

        context = {"errors": errors, "name": name}

        if errors:
            return self.__response(request, context)

        fansub = Fansub.get(id=fansub_id)
        setattr(fansub, "name", name)
        setattr(fansub, "updated_at", datetime.now())
        fansub.save()

        context = {"success": "Fansub edited.", "name": fansub.name}

        return self.__response(request, context)
Beispiel #2
0
    async def post(self, request: Request):
        data = await request.form()

        fansub_id = data.get("id", "")

        try:
            Fansub.get(id=fansub_id)
        except Fansub.DoesNotExist:
            return self.__response(
                request,
                {"error": "The fansub you want to edit doesn't exists."})

        return RedirectResponse(request.url_for("fansub_edit", id=fansub_id),
                                303)
Beispiel #3
0
    async def post(self, request: Request) -> _TemplateResponse:
        data = await request.form()

        name = data.get("name", "")
        fansub_name = data.get("fansub", "")
        url = data.get("url", "")

        errors = []

        if not name:
            errors.append("The field name is mandatory.")

        if not url:
            errors.append("The field url is mandatory.")

        try:
            Anime.get(name=name)
            errors.append("This anime is already in the database.")
        except Anime.DoesNotExist:
            pass

        if errors:
            return self.__response(request, {"errors": errors})

        try:
            fansub = Fansub.get(name=fansub_name)
            fansub_id = fansub.id
        except Fansub.DoesNotExist:
            fansub_id = ""

        Anime.create(name=name, fansub_id=fansub_id, url=url)

        return self.__response(request, {"success": "Anime added."})
Beispiel #4
0
    async def get(self, request: Request) -> _TemplateResponse:
        context = {"request": request}

        anime = []
        for i in Anime.select():
            try:
                fansub = Fansub.get(id=i.fansub_id)
                fansub_name = fansub.name
            except Fansub.DoesNotExist:
                fansub_name = "N.A"

            anime.append({
                "name":
                i.name,
                "url": [{
                    "name": parts.split(";")[0],
                    "href": parts.split(";")[1]
                } for parts in i.url.split(",")] if len(i.url) else [],
                "fansub":
                fansub_name
            })

        context.update({"anime": anime})

        return templates.TemplateResponse("home.html", context)
Beispiel #5
0
    async def post(self, request: Request) -> _TemplateResponse:
        data = await request.form()
        anime_id = request.path_params["id"]

        name = data.get("name", "")
        fansub_name = data.get("fansub", "")
        url = data.get("url", "")

        errors = []

        if not name:
            errors.append("The field name is mandatory.")

        if not fansub_name:
            errors.append("The field fansub is mandatory.")

        if not url:
            errors.append("The field url is mandatory.")

        context = {
            "errors": errors,
            "title": name,
            "current_fansub": fansub_name,
            "url": url.replace(",", "\n")
        }

        if errors:
            return self.__response(request, context)

        anime = Anime.get(id=anime_id)

        try:
            fansub = Fansub.get(name=fansub_name)
            fansub_id = fansub.id
            fansub_name = fansub.name
        except Fansub.DoesNotExist:
            fansub_id = ""
            fansub_name = ""

        setattr(anime, "name", name)
        setattr(anime, "fansub_id", fansub_id)
        setattr(anime, "url", url)
        setattr(anime, "updated_at", datetime.now())

        anime.save()

        context = {
            "success": "Anime edited.",
            "title": anime.name,
            "current_fansub": fansub_name,
            "url": anime.url.replace(",", "\n")
        }

        return self.__response(request, context)
Beispiel #6
0
    async def get(self, request: Request):
        fansub_id = request.path_params["id"]

        try:
            fansub = Fansub.get(id=fansub_id)
        except Fansub.DoesNotExist:
            return RedirectResponse(request.url_for("fansub"))

        context = {"name": fansub.name}

        return self.__response(request, context)
Beispiel #7
0
    async def post(self, request: Request) -> _TemplateResponse:
        data = await request.form()

        fansub_id = data.get("id", "")

        errors = []

        try:
            Fansub.get(id=fansub_id)
        except Fansub.DoesNotExist:
            errors.append(
                "The fansub you want to remove doesn't exists in the database."
            )

        if errors:
            return self.__response(request, {"errors": errors})

        Fansub.get(id=fansub_id).delete_instance()

        context = {"success": "Fansub removed."}

        return self.__response(request, context)
Beispiel #8
0
    async def post(self, request: Request) -> _TemplateResponse:
        data = await request.form()

        name = data.get("name", "")

        errors = []

        if not name:
            errors.append("The field name is mandatory.")

        try:
            Fansub.get(name=name)
            errors.append("This fansub is already exists in the database.")
        except Fansub.DoesNotExist:
            pass

        if errors:
            return self.__response(request, {"errors": errors})

        Fansub.create(name=name)

        context = {"success": "Fansub added."}

        return self.__response(request, context)
Beispiel #9
0
    async def get(self, request: Request):
        anime_id = request.path_params["id"]

        try:
            anime = Anime.get(id=anime_id)
            fansub = Fansub.get(id=anime.fansub_id)
            fansub_name = fansub.name
        except Anime.DoesNotExist:
            return RedirectResponse(request.url_for("anime"))
        except Fansub.DoesNotExist:
            fansub_name = ""

        return self.__response(
            request, {
                "title": anime.name,
                "current_fansub": fansub_name,
                "url": anime.url.replace(",", "\n")
            })