139 lines
3.8 KiB
Python
139 lines
3.8 KiB
Python
from typing import Optional
|
|
|
|
from fastapi import Request
|
|
from folkugat_web.model import temes as model
|
|
from folkugat_web.services.temes import query as temes_q
|
|
from folkugat_web.services.temes.links import guess_link_type
|
|
from folkugat_web.templates import templates
|
|
|
|
|
|
def title(request: Request, logged_in: bool, tema: Optional[model.Tema] = None, tema_id: Optional[int] = None):
|
|
if tema is None:
|
|
if tema_id is None:
|
|
raise ValueError("Either 'tema' or 'tema_id' must be given!")
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/title.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
}
|
|
)
|
|
|
|
|
|
def title_editor(request: Request, logged_in: bool, tema_id: int):
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/editor/title.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
}
|
|
)
|
|
|
|
|
|
def lyric(request: Request, logged_in: bool, tema_id: int, lyric_id: int):
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
if tema is None:
|
|
raise ValueError(f"No tune exists for tema_id: {tema_id}")
|
|
lyric = tema.lyrics.get(lyric_id)
|
|
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/lyric.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
"lyric_id": lyric_id,
|
|
"lyric": lyric,
|
|
}
|
|
)
|
|
|
|
|
|
def lyric_editor(request: Request, logged_in: bool, tema_id: int, lyric_id: int):
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
if tema is None:
|
|
raise ValueError(f"No tune exists for tema_id: {tema_id}")
|
|
lyric = tema.lyrics.get(lyric_id)
|
|
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/editor/lyric.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
"lyric_id": lyric_id,
|
|
"lyric": lyric,
|
|
}
|
|
)
|
|
|
|
|
|
def link(request: Request, logged_in: bool, tema_id: int, link_id: int):
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
if tema is None:
|
|
raise ValueError(f"No tune exists for tema_id: {tema_id}")
|
|
link = tema.links.get(link_id)
|
|
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/link.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
"link_id": link_id,
|
|
"link": link,
|
|
"LinkType": model.LinkType,
|
|
"ContentType": model.ContentType,
|
|
}
|
|
)
|
|
|
|
|
|
def link_editor(request: Request, logged_in: bool, tema_id: int, link_id: int):
|
|
tema = temes_q.get_tema_by_id(tema_id)
|
|
if tema is None:
|
|
raise ValueError(f"No tune exists for tema_id: {tema_id}")
|
|
link = tema.links.get(link_id)
|
|
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/editor/link.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema": tema,
|
|
"link_id": link_id,
|
|
"link": link,
|
|
"LinkType": model.LinkType,
|
|
"ContentType": model.ContentType,
|
|
}
|
|
)
|
|
|
|
|
|
def link_icon(
|
|
request: Request,
|
|
logged_in: bool,
|
|
tema_id: int,
|
|
link_id: int,
|
|
url: str,
|
|
content_type: model.ContentType,
|
|
):
|
|
link = model.Link(
|
|
id=link_id,
|
|
content_type=content_type,
|
|
link_type=guess_link_type(url),
|
|
url=url,
|
|
)
|
|
return templates.TemplateResponse(
|
|
"fragments/tema/link_icon.html",
|
|
{
|
|
"request": request,
|
|
"logged_in": logged_in,
|
|
"tema_id": tema_id,
|
|
"link_id": link_id,
|
|
"link": link,
|
|
"LinkType": model.LinkType,
|
|
"ContentType": model.ContentType,
|
|
}
|
|
)
|