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.User import User
23from puffotter.flask.db.ModelMixin import ModelMixin
24from otaku_info_web.utils.enums import NotificationType
27class NotificationSetting(ModelMixin, db.Model):
28 """
29 Database model that stores notification settings for a user
30 """
32 __tablename__ = "notification_settings"
33 """
34 The name of the database table
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 user_id: int = db.Column(
46 db.Integer,
47 db.ForeignKey(
48 "users.id", ondelete="CASCADE", onupdate="CASCADE"
49 ),
50 nullable=False
51 )
52 """
53 The ID of the user associated with this notification setting
54 """
56 user: User = db.relationship(
57 "User",
58 backref=db.backref(
59 "notification_settings", lazy=True, cascade="all,delete"
60 )
61 )
62 """
63 The user associated with this notification setting
64 """
66 notification_type: str = \
67 db.Column(db.Enum(NotificationType), nullable=False)
68 """
69 The notification type
70 """
72 value: bool = db.Column(db.Boolean, nullable=False, default=False)
73 """
74 Whether or not the notification is active or not
75 """
77 def __json__(self, include_children: bool = False) -> Dict[str, Any]:
78 """
79 Generates a dictionary containing the information of this model
80 :param include_children: Specifies if children data models
81 will be included or if they're limited to IDs
82 :return: A dictionary representing the model's values
83 """
84 data = {
85 "id": self.id,
86 "notification_type": self.notification_type,
87 "value": self.value
88 }
89 if include_children:
90 data["user"] = self.user.__json__(include_children)
91 return data