2023-04-09 19:12:35 +00:00
|
|
|
"""
|
|
|
|
OnlyLegs - Database models and ions for SQLAlchemy
|
|
|
|
"""
|
|
|
|
from uuid import uuid4
|
|
|
|
from flask_login import UserMixin
|
2023-04-12 16:58:13 +00:00
|
|
|
from onlylegs.extensions import db
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
class GroupJunction(db.Model): # pylint: disable=too-few-public-methods, C0103
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:16:43 +00:00
|
|
|
Junction table for posts and groups
|
|
|
|
Joins with posts and groups
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
__tablename__ = "group_junction"
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-04-12 15:16:43 +00:00
|
|
|
|
|
|
|
group_id = db.Column(db.Integer, db.ForeignKey("group.id"))
|
|
|
|
post_id = db.Column(db.Integer, db.ForeignKey("post.id"))
|
|
|
|
|
|
|
|
date_added = db.Column(
|
2023-04-09 19:12:35 +00:00
|
|
|
db.DateTime,
|
|
|
|
nullable=False,
|
|
|
|
server_default=db.func.now(), # pylint: disable=E1102
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
class Post(db.Model): # pylint: disable=too-few-public-methods, C0103
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
|
|
|
Post table
|
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
__tablename__ = "post"
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-09 19:12:35 +00:00
|
|
|
filename = db.Column(db.String, unique=True, nullable=False)
|
|
|
|
mimetype = db.Column(db.String, nullable=False)
|
|
|
|
exif = db.Column(db.PickleType, nullable=False)
|
|
|
|
colours = db.Column(db.PickleType, nullable=False)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-09 19:12:35 +00:00
|
|
|
description = db.Column(db.String, nullable=False)
|
|
|
|
alt = db.Column(db.String, nullable=False)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
created_at = db.Column(
|
|
|
|
db.DateTime,
|
|
|
|
nullable=False,
|
|
|
|
server_default=db.func.now(), # pylint: disable=E1102
|
|
|
|
)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-09 19:12:35 +00:00
|
|
|
junction = db.relationship("GroupJunction", backref="posts")
|
|
|
|
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
class Group(db.Model): # pylint: disable=too-few-public-methods, C0103
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
|
|
|
Group table
|
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
__tablename__ = "group"
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-09 19:12:35 +00:00
|
|
|
name = db.Column(db.String, nullable=False)
|
|
|
|
description = db.Column(db.String, nullable=False)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
|
2023-04-09 19:12:35 +00:00
|
|
|
created_at = db.Column(
|
|
|
|
db.DateTime,
|
|
|
|
nullable=False,
|
|
|
|
server_default=db.func.now(), # pylint: disable=E1102
|
|
|
|
)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-09 19:12:35 +00:00
|
|
|
junction = db.relationship("GroupJunction", backref="groups")
|
|
|
|
|
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
class User(db.Model, UserMixin): # pylint: disable=too-few-public-methods, C0103
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:16:43 +00:00
|
|
|
User table
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
__tablename__ = "user"
|
2023-04-09 19:12:35 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
# Gallery used information
|
2023-04-09 19:12:35 +00:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-04-12 15:16:43 +00:00
|
|
|
alt_id = db.Column(db.String, unique=True, nullable=False, default=str(uuid4()))
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-04-20 13:58:40 +00:00
|
|
|
picture = db.Column(db.String, nullable=True, default=None)
|
|
|
|
picture_colour = db.Column(db.String, nullable=True, default=None)
|
|
|
|
banner = db.Column(db.String, nullable=True, default=None)
|
|
|
|
bannner_colour = db.Column(db.String, nullable=True, default=None)
|
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
username = db.Column(db.String, unique=True, nullable=False)
|
|
|
|
email = db.Column(db.String, unique=True, nullable=False)
|
|
|
|
password = db.Column(db.String, nullable=False)
|
|
|
|
joined_at = db.Column(
|
2023-04-09 19:12:35 +00:00
|
|
|
db.DateTime,
|
|
|
|
nullable=False,
|
|
|
|
server_default=db.func.now(), # pylint: disable=E1102
|
|
|
|
)
|
2023-04-12 15:18:13 +00:00
|
|
|
|
|
|
|
posts = db.relationship("Post", backref="author")
|
|
|
|
groups = db.relationship("Group", backref="author")
|
2023-04-09 19:12:35 +00:00
|
|
|
|
2023-04-12 15:16:43 +00:00
|
|
|
def get_id(self):
|
|
|
|
return str(self.alt_id)
|