Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2020 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of otaku-info-web.
6otaku-info-web is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11otaku-info-web is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with otaku-info-web. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import Dict, Any, Optional
21from puffotter.flask.base import db
22from puffotter.flask.db.ModelMixin import ModelMixin
23from otaku_info_web.utils.db_model_helper import build_title
24from otaku_info_web.utils.enums import ReleasingState, MediaType, MediaSubType
27class MediaItem(ModelMixin, db.Model):
28 """
29 Database model for media items.
30 These model a generic, site-agnostic representation of a series.
31 """
33 __tablename__ = "media_items"
34 """
35 The name of the database table
36 """
38 __table_args__ = (
39 db.UniqueConstraint(
40 "media_type",
41 "media_subtype",
42 "romaji_title",
43 "cover_url",
44 name="unique_media_item"
45 ),
46 )
47 """
48 Makes sure that objects that should be unique are unique
49 """
51 def __init__(self, *args, **kwargs):
52 """
53 Initializes the Model
54 :param args: The constructor arguments
55 :param kwargs: The constructor keyword arguments
56 """
57 super().__init__(*args, **kwargs)
59 media_type: MediaType = db.Column(db.Enum(MediaType), nullable=False)
60 """
61 The media type of the list item
62 """
64 media_subtype: MediaSubType = db.Column(
65 db.Enum(MediaSubType), nullable=False
66 )
67 """
68 The subtype (for example, TV short, movie oneshot etc)
69 """
71 english_title: Optional[str] = db.Column(db.Unicode(255), nullable=True)
72 """
73 The English title of the media item
74 """
76 romaji_title: str = db.Column(db.Unicode(255), nullable=False)
77 """
78 The Japanese title of the media item written in Romaji
79 """
81 cover_url: str = db.Column(db.String(255), nullable=False)
82 """
83 An URL to a cover image of the media item
84 """
86 latest_release: Optional[int] = db.Column(db.Integer, nullable=True)
87 """
88 The latest release chapter/episode for this media item
89 """
91 releasing_state: ReleasingState = db.Column(
92 db.Enum(ReleasingState), nullable=False
93 )
94 """
95 The current releasing state of the media item
96 """
98 @property
99 def title(self) -> str:
100 """
101 :return: The default title for the media item.
102 """
103 return build_title(self.english_title, self.romaji_title)
105 def __json__(self, include_children: bool = False) -> Dict[str, Any]:
106 """
107 Generates a dictionary containing the information of this model
108 :param include_children: Specifies if children data models
109 will be included or if they're limited to IDs
110 :return: A dictionary representing the model's values
111 """
112 data = {
113 "id": self.id,
114 "media_type": self.media_type.value,
115 "media_subtype": self.media_subtype.value,
116 "english_title": self.english_title,
117 "romaji_title": self.romaji_title,
118 "cover_url": self.cover_url,
119 "latest_release": self.latest_release,
120 "releasing_state": self.releasing_state.value
121 }
122 return data