70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import asyncio
|
|
from pathlib import Path
|
|
import os
|
|
|
|
import inject
|
|
import markdown
|
|
from litestar import (
|
|
Controller,
|
|
get,
|
|
post,
|
|
MediaType,
|
|
Litestar,
|
|
)
|
|
from litestar.enums import RequestEncodingType
|
|
from litestar.datastructures import UploadFile
|
|
from litestar.params import Body
|
|
from litestar.exceptions import HTTPException
|
|
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
from litestar.template.config import TemplateConfig
|
|
from litestar.response import Template
|
|
from litestar.static_files import create_static_files_router
|
|
|
|
from server.infra import logger
|
|
from server.config import get_app_config
|
|
from server.infra.cache import LocalCacheRepository
|
|
from server.infra.db import AsyncDB
|
|
from server.modules.descriptions import CharactersService, Breed, CharactersRepository
|
|
from server.modules.recognizer import RecognizerService, RecognizerRepository
|
|
|
|
class DescriptionController(Controller):
|
|
path = "/"
|
|
|
|
@get("/")
|
|
async def dogs(self) -> Template:
|
|
return Template(template_name="dogs.html")
|
|
|
|
@get("/cats")
|
|
async def cats(self) -> Template:
|
|
return Template(template_name="cats.html")
|
|
|
|
@get("/contacts")
|
|
async def contacts(self) -> Template:
|
|
return Template(template_name="contacts.html")
|
|
|
|
@get("/donate")
|
|
async def donate(self) -> Template:
|
|
return Template(template_name="donate.html")
|
|
|
|
@get("/dogs-characteristics")
|
|
async def dogs_characteristics(self) -> Template:
|
|
breeds = await characters_service.get_characters()
|
|
return Template(
|
|
template_name="dogs-characteristics.html", context={"breeds": breeds}
|
|
)
|
|
|
|
@get("/dogs-characteristics/{name:str}")
|
|
async def beer_description(self, name: str) -> Template:
|
|
breed = await characters_service.get_character(name)
|
|
if breed is None:
|
|
raise HTTPException(status_code=404, detail="Порода не найдена")
|
|
images = await recognizer_service.images_dogs()
|
|
return Template(
|
|
template_name="beers-description.html",
|
|
context={
|
|
"text": markdown.markdown(breed.description),
|
|
"title": breed.name,
|
|
"images": [f"/static/assets/dog/{name}/{i}" for i in images[name]],
|
|
},
|
|
)
|
|
|