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-09-24 18:53:14 +00:00
|
|
|
class AlbumJunction(db.Model):
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-08-04 17:34:08 +00:00
|
|
|
Junction table for picturess and albums
|
|
|
|
Joins with picturess and albums
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
__tablename__ = "album_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
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
album_id = db.Column(db.Integer, db.ForeignKey("albums.id"))
|
|
|
|
picture_id = db.Column(db.Integer, db.ForeignKey("pictures.id"))
|
2023-04-12 15:16:43 +00:00
|
|
|
|
|
|
|
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-09-24 18:53:14 +00:00
|
|
|
class Pictures(db.Model):
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-08-04 17:34:08 +00:00
|
|
|
Pictures table
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
__tablename__ = "pictures"
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-08-04 17:34:08 +00:00
|
|
|
author_id = db.Column(db.Integer, db.ForeignKey("users.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)
|
|
|
|
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-08-04 17:34:08 +00:00
|
|
|
album_fk = db.relationship("AlbumJunction", backref="pictures")
|
2023-09-24 18:53:14 +00:00
|
|
|
exif_fk = db.relationship("Exif", backref="pictures")
|
2023-04-09 19:12:35 +00:00
|
|
|
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-09-24 18:53:14 +00:00
|
|
|
class Exif(db.Model):
|
|
|
|
"""
|
|
|
|
Exif data for pictures
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "exif"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
picture_id = db.Column(db.Integer, db.ForeignKey("pictures.id"))
|
|
|
|
|
|
|
|
key = db.Column(db.String, nullable=False)
|
2023-09-26 18:36:49 +00:00
|
|
|
value = db.Column(db.PickleType, nullable=False)
|
2023-09-24 18:53:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Albums(db.Model):
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-08-04 17:34:08 +00:00
|
|
|
albums table
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
__tablename__ = "albums"
|
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-08-04 17:34:08 +00:00
|
|
|
author_id = db.Column(db.Integer, db.ForeignKey("users.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-08-04 17:34:08 +00:00
|
|
|
album_fk = db.relationship("AlbumJunction", backref="albums")
|
2023-04-09 19:12:35 +00:00
|
|
|
|
|
|
|
|
2023-09-24 18:53:14 +00:00
|
|
|
class Users(db.Model, UserMixin):
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-08-04 17:34:08 +00:00
|
|
|
Users table
|
2023-04-09 19:12:35 +00:00
|
|
|
"""
|
2023-04-12 15:18:13 +00:00
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
__tablename__ = "users"
|
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 19:21:28 +00:00
|
|
|
picture = db.Column(db.String, default=None)
|
2023-04-20 20:47:04 +00:00
|
|
|
colour = db.Column(db.PickleType, default=None)
|
2023-04-20 19:21:28 +00:00
|
|
|
banner = db.Column(db.String, default=None)
|
2023-04-20 17:38:44 +00:00
|
|
|
|
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
|
|
|
|
2023-08-04 17:34:08 +00:00
|
|
|
pictures_fk = db.relationship("Pictures", backref="author")
|
|
|
|
albums_fk = db.relationship("Albums", 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)
|