Rendering code refactor
This commit is contained in:
@@ -5,7 +5,11 @@ from folkugat_web.model import temes as model
|
||||
|
||||
|
||||
def get_tema_by_id(tema_id: int) -> model.Tema | None:
|
||||
return temes_q.get_tema_by_id(tema_id)
|
||||
return temes_q.get_tema_by_id(tema_id=tema_id)
|
||||
|
||||
|
||||
def get_temes_by_ids(tema_ids: list[int]) -> list[model.Tema]:
|
||||
return temes_q.get_temes_by_ids(tema_ids=tema_ids)
|
||||
|
||||
|
||||
def tema_compute_stats(
|
||||
|
||||
@@ -3,6 +3,7 @@ from collections.abc import Iterable, Iterator
|
||||
from fastapi import HTTPException
|
||||
from folkugat_web.dal.sql.temes import scores as scores_dal
|
||||
from folkugat_web.model import temes as model
|
||||
from folkugat_web.model.lilypond import score as lilypond_model
|
||||
from folkugat_web.services import lilypond
|
||||
from folkugat_web.services.temes import lyrics as lyrics_service
|
||||
from folkugat_web.services.temes import properties as properties_service
|
||||
@@ -46,13 +47,29 @@ def create_score(tema_id: int) -> model.Score:
|
||||
return scores_dal.insert_score(score=new_score)
|
||||
|
||||
|
||||
def build_single_tune_full_source(tema_id: int, source: str) -> str:
|
||||
tema = temes_q.get_tema_by_id(tema_id)
|
||||
if not tema:
|
||||
raise HTTPException(status_code=404, detail="Could not find tema!")
|
||||
tema = (
|
||||
FnChain.transform(tema) |
|
||||
properties_service.add_properties_to_tema |
|
||||
lyrics_service.add_lyrics_to_tema
|
||||
def build_tune_set_full_source(tema_ids: list[int]) -> str:
|
||||
temes = (
|
||||
FnChain.transform(temes_q.get_temes_by_ids(tema_ids=tema_ids)) |
|
||||
properties_service.add_properties_to_temes |
|
||||
lyrics_service.add_lyrics_to_temes |
|
||||
add_scores_to_temes |
|
||||
list
|
||||
).result()
|
||||
return lilypond.source_to_single_score(source=source, tema=tema)
|
||||
if not temes:
|
||||
return ""
|
||||
set_title = " i ".join(filter(bool, [
|
||||
", ".join([tema.title for tema in temes[:-1]]),
|
||||
temes[-1].title
|
||||
]))
|
||||
tune_set = lilypond_model.LilypondSet(
|
||||
title=set_title,
|
||||
tunes=[
|
||||
lilypond_model.LilypondTune(
|
||||
header=lilypond_model.HeaderData.from_tema(tema=tema),
|
||||
score_source=tema.scores[0].source if tema.scores else None,
|
||||
lyrics=lilypond_model.LyricsText.from_lyrics(lyrics=tema.lyrics[0]) if tema.lyrics else None,
|
||||
) for tema in temes
|
||||
]
|
||||
)
|
||||
print("TUNE SET HASH: ", tune_set.hash().hex())
|
||||
return lilypond.tune_set_score(tune_set=tune_set)
|
||||
|
||||
Reference in New Issue
Block a user