Coverage for otaku_info/db/MediaUserState.py: 87%
Shortcuts 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
Shortcuts 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.
6otaku-info 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 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. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import Optional, TYPE_CHECKING, List
21from jerrycan.base import db
22from jerrycan.db.User import User
23from jerrycan.db.ModelMixin import ModelMixin
24from otaku_info.db.MediaItem import MediaItem
25from otaku_info.enums import ConsumingState, ListService, MediaType
26if TYPE_CHECKING: 26 ↛ 27line 26 didn't jump to line 27, because the condition on line 26 was never true
27 from otaku_info.db.MediaNotification import MediaNotification
28 from otaku_info.db.MediaListItem import MediaListItem
31class MediaUserState(ModelMixin, db.Model):
32 """
33 Database model that keeps track of a user's entries on external services
34 for a media item
35 """
37 def __init__(self, *args, **kwargs):
38 """
39 Initializes the Model
40 :param args: The constructor arguments
41 :param kwargs: The constructor keyword arguments
42 """
43 super().__init__(*args, **kwargs)
45 __tablename__ = "media_user_states"
46 __table_args__ = (db.ForeignKeyConstraint(
47 ("service", "service_id", "media_type"),
48 (MediaItem.service, MediaItem.service_id, MediaItem.media_type)
49 ),)
51 service: ListService = db.Column(db.Enum(ListService), primary_key=True)
52 service_id: str = db.Column(db.String(255), primary_key=True)
53 media_type: MediaType = db.Column(db.Enum(MediaType), primary_key=True)
54 user_id: int = db.Column(
55 db.Integer,
56 db.ForeignKey(
57 "users.id", ondelete="CASCADE", onupdate="CASCADE"
58 ),
59 primary_key=True
60 )
62 progress: Optional[int] = db.Column(db.Integer, nullable=True)
63 volume_progress: Optional[int] = db.Column(db.Integer, nullable=True)
64 score: Optional[int] = db.Column(db.Integer, nullable=True)
65 consuming_state: ConsumingState \
66 = db.Column(db.Enum(ConsumingState), nullable=False)
68 media_item: MediaItem = db.relationship(
69 "MediaItem", back_populates="user_states"
70 )
71 user: User = db.relationship(
72 "User",
73 backref=db.backref(
74 "media_user_states", lazy=True, cascade="all,delete"
75 )
76 )
77 media_notification: Optional["MediaNotification"] = db.relationship(
78 "MediaNotification",
79 uselist=False,
80 back_populates="media_user_state",
81 cascade="all, delete"
82 )
83 media_list_items: List["MediaListItem"] = db.relationship(
84 "MediaListItem", back_populates="user_state", cascade="all, delete"
85 )