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
21from puffotter.flask.base import db
22from puffotter.flask.db.ModelMixin import ModelMixin
23from otaku_info_web.db.MediaUserState import MediaUserState
26class MediaNotification(ModelMixin, db.Model):
27 """
28 Database model that stores a media notification for a user
29 """
31 __tablename__ = "media_notifications"
32 """
33 The name of the database table
34 """
36 def __init__(self, *args, **kwargs):
37 """
38 Initializes the Model
39 :param args: The constructor arguments
40 :param kwargs: The constructor keyword arguments
41 """
42 super().__init__(*args, **kwargs)
44 media_user_state_id: int = db.Column(
45 db.Integer,
46 db.ForeignKey(
47 "media_user_states.id", ondelete="CASCADE", onupdate="CASCADE"
48 ),
49 nullable=False,
50 unique=True
51 )
52 """
53 The ID of the media user state this notification references
54 """
56 media_user_state: MediaUserState = db.relationship(
57 "MediaUserState",
58 backref=db.backref(
59 "media_notifications", lazy=True, cascade="all,delete"
60 )
61 )
62 """
63 The media user state this notification references
64 """
66 last_update = db.Column(db.Integer, nullable=False)
67 """
68 The last update value sent to the user
69 """
71 def __json__(self, include_children: bool = False) -> Dict[str, Any]:
72 """
73 Generates a dictionary containing the information of this model
74 :param include_children: Specifies if children data models
75 will be included or if they're limited to IDs
76 :return: A dictionary representing the model's values
77 """
78 data = {
79 "id": self.id,
80 "media_user_state_id": self.media_user_state_id,
81 "last_update": self.last_update
82 }
83 if include_children:
84 data["user"] = self.user.__json__(include_children)
85 data["media_user_state"] = \
86 self.media_user_state.__json__(include_children)
87 return data