Skip to content

Commit

Permalink
added base model
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Jul 16, 2024
1 parent 427abcb commit 0e90fae
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
36 changes: 36 additions & 0 deletions nlightreader/models/base_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from PySide6.QtCore import QLocale


class BaseModel:
def __init__(self, content_id: str, catalog_id: int):
self.__id = f"|{catalog_id}|_|{content_id}|"
Expand All @@ -24,3 +27,36 @@ def catalog_id(self):

def to_dict(self) -> dict:
raise NotImplementedError


class NamedBaseModel(BaseModel):
def __init__(
self,
content_id: str,
catalog_id: int,
name: str,
russian: str,
):
super().__init__(content_id, catalog_id)
self.__name = name
self.__russian = russian

@property
def name(self):
return self.__name

@property
def russian(self):
return self.__russian

def get_name(self) -> str:
if (
QLocale().language()
in (
QLocale.Language.Russian,
QLocale.Language.Ukrainian,
)
and self.__russian
):
return self.__russian
return self.__name
32 changes: 5 additions & 27 deletions nlightreader/models/manga_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
from PySide6.QtCore import QLocale

from nlightreader.consts.enums import Nl
from nlightreader.models.base_model import BaseModel
from nlightreader.models.base_model import NamedBaseModel


class Manga(BaseModel):
class Manga(NamedBaseModel):
def __init__(
self,
content_id: str,
catalog_id: int,
name: str,
russian: str,
):
super().__init__(content_id, catalog_id)
super().__init__(content_id, catalog_id, name, russian)

self.__name = name
self.__russian = russian
self.__kind: Nl.MangaKind = Nl.MangaKind.undefined
self.__status: Nl.MangaStatus = Nl.MangaStatus.undefined
self.__score: int | float = 0
Expand All @@ -30,14 +28,6 @@ def __init__(

self.__descriptions: dict[Nl.Language, str] = {}

@property
def name(self):
return self.__name

@property
def russian(self):
return self.__russian

@property
def kind(self):
return self.__kind
Expand Down Expand Up @@ -103,18 +93,6 @@ def chapters(self, chapters: int):
raise TypeError(f"Chapters must be int got {type(chapters)}")
self.__chapters = chapters

def get_name(self) -> str:
if (
QLocale().language()
in (
QLocale.Language.Russian,
QLocale.Language.Ukrainian,
)
and self.__russian
):
return self.__russian
return self.__name

def add_description(self, language: Nl.Language, description: str):
if not isinstance(language, Nl.Language):
raise TypeError(
Expand Down Expand Up @@ -164,8 +142,8 @@ def to_dict(self) -> dict:
"id": self.id,
"content_id": self.content_id,
"catalog_id": self.catalog_id,
"name": self.__name,
"russian": self.__russian,
"name": self.name,
"russian": self.russian,
"kind": self.kind.name,
"description": self.descriptions_to_str(),
"score": self.score,
Expand Down

0 comments on commit 0e90fae

Please sign in to comment.