Added tune previews

This commit is contained in:
marc
2025-04-27 17:00:04 +02:00
parent 695e0b54bf
commit bc3d98aba2
14 changed files with 123 additions and 131 deletions

View File

@@ -79,6 +79,7 @@ def create_scores_table(con: Connection):
errors TEXT NOT NULL,
img_url TEXT,
pdf_url TEXT,
preview_url TEXT,
hidden BOOLEAN,
FOREIGN KEY(tema_id) REFERENCES temes(id) ON DELETE CASCADE
)

View File

@@ -6,7 +6,7 @@ from folkugat_web.dal.sql import Connection, get_connection
from folkugat_web.model import temes as model
from folkugat_web.model.lilypond.processing import RenderError
ScoreRowTuple = tuple[int, int, str, str, str, str | None, str | None, bool]
ScoreRowTuple = tuple[int, int, str, str, str, str | None, str | None, str | None, bool]
class ScoreRowDict(TypedDict):
@@ -17,6 +17,7 @@ class ScoreRowDict(TypedDict):
source: str
img_url: str | None
pdf_url: str | None
preview_url: str | None
hidden: bool
@@ -29,6 +30,7 @@ def score_to_row(score: model.Score) -> ScoreRowDict:
"source": score.source,
"img_url": score.img_url,
"pdf_url": score.pdf_url,
"preview_url": score.preview_url,
"hidden": score.hidden,
}
@@ -43,7 +45,8 @@ def row_to_score(row: ScoreRowTuple) -> model.Score:
errors=list(map(RenderError.from_dict, errors_dicts)),
img_url=row[5],
pdf_url=row[6],
hidden=bool(row[7]),
preview_url=row[7],
hidden=bool(row[8]),
)
@@ -78,7 +81,7 @@ def get_scores(score_id: int | None = None, tema_id: int | None = None, con: Con
query = f"""
SELECT
id, tema_id, title, source, errors, img_url, pdf_url, hidden
id, tema_id, title, source, errors, img_url, pdf_url, preview_url, hidden
FROM tema_scores
{filter_clause}
"""
@@ -92,9 +95,9 @@ def insert_score(score: model.Score, con: Connection | None = None) -> model.Sco
data = score_to_row(score)
query = f"""
INSERT INTO tema_scores
(id, tema_id, title, source, errors, img_url, pdf_url, hidden)
(id, tema_id, title, source, errors, img_url, pdf_url, preview_url, hidden)
VALUES
(:id, :tema_id, :title, :source, :errors, :img_url, :pdf_url, :hidden)
(:id, :tema_id, :title, :source, :errors, :img_url, :pdf_url, :preview_url, :hidden)
RETURNING *
"""
with get_connection(con) as con:
@@ -110,7 +113,7 @@ def update_score(score: model.Score, con: Connection | None = None):
UPDATE tema_scores
SET
tema_id = :tema_id, title = :title, source = :source, errors = :errors,
img_url = :img_url, pdf_url = :pdf_url, hidden = :hidden
img_url = :img_url, pdf_url = :pdf_url, preview_url = :preview_url, hidden = :hidden
WHERE
id = :id
"""