Added lilypond edition
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
import itertools
|
||||
from typing import Self
|
||||
|
||||
from folkugat_web.model.lilypond import RenderError
|
||||
from folkugat_web.model.search import NGrams
|
||||
from folkugat_web.model.sessions import Session
|
||||
from folkugat_web.services import ngrams
|
||||
@@ -55,6 +58,33 @@ class Lyrics:
|
||||
content: str
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Score:
|
||||
id: int | None
|
||||
tema_id: int
|
||||
title: str
|
||||
errors: list[RenderError]
|
||||
source: str
|
||||
img_url: str | None
|
||||
pdf_url: str | None
|
||||
hidden: bool
|
||||
|
||||
@classmethod
|
||||
def from_link(cls, link: Link) -> Self:
|
||||
if link.link_type not in {LinkType.IMAGE, LinkType.PDF}:
|
||||
raise ValueError("Link not supported to build a score!")
|
||||
return cls(
|
||||
id=None,
|
||||
tema_id=link.tema_id,
|
||||
title=link.title,
|
||||
source="",
|
||||
errors=[],
|
||||
img_url=link.url if link.link_type is LinkType.IMAGE else None,
|
||||
pdf_url=link.url if link.link_type is LinkType.PDF else None,
|
||||
hidden=False,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Stats:
|
||||
times_played: int
|
||||
@@ -69,6 +99,7 @@ class Tema:
|
||||
properties: list[Property] = dataclasses.field(default_factory=list)
|
||||
links: list[Link] = dataclasses.field(default_factory=list)
|
||||
lyrics: list[Lyrics] = dataclasses.field(default_factory=list)
|
||||
scores: list[Score] = dataclasses.field(default_factory=list)
|
||||
# Search related
|
||||
alternatives: list[str] = dataclasses.field(default_factory=list)
|
||||
hidden: bool = True
|
||||
@@ -89,9 +120,18 @@ class Tema:
|
||||
return link.url.startswith("/")
|
||||
return link.link_type is LinkType.IMAGE
|
||||
|
||||
def score(self) -> Link | None:
|
||||
result = next(filter(self._is_score, self.links), None)
|
||||
return result
|
||||
def main_score(self) -> Score | None:
|
||||
candidate_scores = filter(lambda s: s.hidden is False, self.scores)
|
||||
candidate_links = map(Score.from_link, filter(self._is_score, self.links))
|
||||
return next(itertools.chain(candidate_scores, candidate_links), None)
|
||||
|
||||
def composer(self) -> str | None:
|
||||
result = next(filter(lambda prop: prop.field is PropertyField.AUTOR, self.properties), None)
|
||||
return result.value if result else None
|
||||
|
||||
def origin(self) -> str | None:
|
||||
result = next(filter(lambda prop: prop.field is PropertyField.ORIGEN, self.properties), None)
|
||||
return result.value if result else None
|
||||
|
||||
|
||||
class TemaCols(enum.Enum):
|
||||
|
||||
Reference in New Issue
Block a user