Migrated links, lyrics and properties
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
from typing import Self
|
||||
|
||||
from folkugat_web.model.search import NGrams
|
||||
from folkugat_web.model.sessions import Session
|
||||
from folkugat_web.services import ngrams
|
||||
|
||||
from ._base import IndexedList, WithId
|
||||
|
||||
|
||||
class ContentType(enum.Enum):
|
||||
PARTITURA = "partitura"
|
||||
@@ -26,31 +23,14 @@ class LinkType(enum.Enum):
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Link(WithId):
|
||||
class Link:
|
||||
id: int | None
|
||||
tema_id: int
|
||||
content_type: ContentType
|
||||
link_type: LinkType | None
|
||||
url: str
|
||||
title: str = ""
|
||||
|
||||
def to_dict(self):
|
||||
return dict(
|
||||
id=self.id,
|
||||
content_type=self.content_type.value,
|
||||
link_type=self.link_type.value if self.link_type else None,
|
||||
url=self.url,
|
||||
title=self.title,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d):
|
||||
return cls(
|
||||
id=d["id"],
|
||||
content_type=ContentType(d["content_type"]),
|
||||
link_type=LinkType(d["link_type"]) if d["link_type"] else None,
|
||||
url=d["url"],
|
||||
title=d["title"],
|
||||
)
|
||||
|
||||
|
||||
class PropertyField(enum.Enum):
|
||||
AUTOR = "autor"
|
||||
@@ -60,46 +40,20 @@ class PropertyField(enum.Enum):
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Property(WithId):
|
||||
class Property:
|
||||
id: int | None
|
||||
tema_id: int
|
||||
field: PropertyField
|
||||
value: str
|
||||
|
||||
def to_dict(self):
|
||||
return dict(
|
||||
id=self.id,
|
||||
field=self.field.value,
|
||||
value=self.value,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d):
|
||||
return cls(
|
||||
id=d["id"],
|
||||
field=PropertyField(d["field"]),
|
||||
value=d["value"],
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Lyrics(WithId):
|
||||
class Lyrics:
|
||||
id: int | None
|
||||
tema_id: int
|
||||
title: str
|
||||
content: str
|
||||
|
||||
def to_dict(self):
|
||||
return dict(
|
||||
id=self.id,
|
||||
title=self.title,
|
||||
content=self.content,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d) -> Self:
|
||||
return cls(
|
||||
id=d["id"],
|
||||
title=d["title"],
|
||||
content=d["content"],
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Stats:
|
||||
@@ -112,12 +66,11 @@ class Tema:
|
||||
id: int | None = None
|
||||
# Info
|
||||
title: str = ""
|
||||
properties: IndexedList[Property] = dataclasses.field(default_factory=IndexedList)
|
||||
links: IndexedList[Link] = dataclasses.field(default_factory=IndexedList)
|
||||
lyrics: IndexedList[Lyrics] = dataclasses.field(default_factory=IndexedList)
|
||||
properties: list[Property] = dataclasses.field(default_factory=list)
|
||||
links: list[Link] = dataclasses.field(default_factory=list)
|
||||
lyrics: list[Lyrics] = dataclasses.field(default_factory=list)
|
||||
# Search related
|
||||
alternatives: list[str] = dataclasses.field(default_factory=list)
|
||||
ngrams: NGrams = dataclasses.field(default_factory=dict)
|
||||
hidden: bool = True
|
||||
# Other info
|
||||
modification_date: datetime.datetime = dataclasses.field(default_factory=datetime.datetime.now)
|
||||
@@ -125,12 +78,8 @@ class Tema:
|
||||
# Stats
|
||||
stats: Stats | None = None
|
||||
|
||||
def compute_ngrams(self):
|
||||
self.ngrams = ngrams.get_text_ngrams(self.title, *self.alternatives)
|
||||
|
||||
def with_ngrams(self):
|
||||
self.compute_ngrams()
|
||||
return self
|
||||
def ngrams(self) -> NGrams:
|
||||
return ngrams.get_text_ngrams(self.title, *self.alternatives)
|
||||
|
||||
@staticmethod
|
||||
def _is_score(link: Link) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user