mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Move most of the processing into the upload
This commit is contained in:
parent
970d3dcf66
commit
0a27d79a82
8 changed files with 107 additions and 100 deletions
|
@ -6,8 +6,8 @@ import os
|
|||
from datetime import datetime
|
||||
import platformdirs
|
||||
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import declarative_base, relationship
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey, PickleType
|
||||
from sqlalchemy.orm import declarative_base, relationship, backref, mapped_column
|
||||
|
||||
|
||||
path_to_db = os.path.join(platformdirs.user_config_dir('onlylegs'), 'gallery.sqlite')
|
||||
|
@ -15,7 +15,7 @@ engine = create_engine(f'sqlite:///{path_to_db}', echo=False)
|
|||
base = declarative_base()
|
||||
|
||||
|
||||
class users (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Users (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
User table
|
||||
Joins with post, groups, session and log
|
||||
|
@ -28,19 +28,13 @@ class users (base): # pylint: disable=too-few-public-methods, C0103
|
|||
password = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
posts = relationship('posts')
|
||||
groups = relationship('groups')
|
||||
session = relationship('sessions')
|
||||
log = relationship('logs')
|
||||
|
||||
def __init__(self, username, email, password):
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.created_at = datetime.now()
|
||||
posts = relationship('Posts', backref='users')
|
||||
groups = relationship('Groups', backref='users')
|
||||
session = relationship('Sessions', backref='users')
|
||||
log = relationship('Logs', backref='users')
|
||||
|
||||
|
||||
class posts (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Posts (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Post table
|
||||
Joins with group_junction
|
||||
|
@ -48,23 +42,22 @@ class posts (base): # pylint: disable=too-few-public-methods, C0103
|
|||
__tablename__ = 'posts'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
file_name = Column(String, unique=True, nullable=False)
|
||||
description = Column(String, nullable=False)
|
||||
alt = Column(String, nullable=False)
|
||||
author_id = Column(Integer, ForeignKey('users.id'))
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
file_name = Column(String, unique=True, nullable=False)
|
||||
file_type = Column(String, nullable=False)
|
||||
|
||||
image_exif = Column(PickleType, nullable=False)
|
||||
image_colours = Column(PickleType, nullable=False)
|
||||
|
||||
post_description = Column(String, nullable=False)
|
||||
post_alt = Column(String, nullable=False)
|
||||
|
||||
junction = relationship('group_junction')
|
||||
|
||||
def __init__(self, file_name, description, alt, author_id):
|
||||
self.file_name = file_name
|
||||
self.description = description
|
||||
self.alt = alt
|
||||
self.author_id = author_id
|
||||
self.created_at = datetime.now()
|
||||
junction = relationship('GroupJunction', backref='posts')
|
||||
|
||||
|
||||
class groups (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Groups (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Group table
|
||||
Joins with group_junction
|
||||
|
@ -77,16 +70,10 @@ class groups (base): # pylint: disable=too-few-public-methods, C0103
|
|||
author_id = Column(Integer, ForeignKey('users.id'))
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
junction = relationship('group_junction')
|
||||
|
||||
def __init__(self, name, description, author_id):
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.author_id = author_id
|
||||
self.created_at = datetime.now()
|
||||
junction = relationship('GroupJunction', backref='groups')
|
||||
|
||||
|
||||
class group_junction (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class GroupJunction (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Junction table for posts and groups
|
||||
Joins with posts and groups
|
||||
|
@ -97,12 +84,8 @@ class group_junction (base): # pylint: disable=too-few-public-methods, C0103
|
|||
group_id = Column(Integer, ForeignKey('groups.id'))
|
||||
post_id = Column(Integer, ForeignKey('posts.id'))
|
||||
|
||||
def __init__(self, group_id, post_id):
|
||||
self.group_id = group_id
|
||||
self.post_id = post_id
|
||||
|
||||
|
||||
class sessions (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Sessions (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Session table
|
||||
Joins with user
|
||||
|
@ -117,16 +100,8 @@ class sessions (base): # pylint: disable=too-few-public-methods, C0103
|
|||
active = Column(Boolean, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, user_id, session_uuid, ip_address, user_agent, active): # pylint: disable=too-many-arguments, C0103
|
||||
self.user_id = user_id
|
||||
self.session_uuid = session_uuid
|
||||
self.ip_address = ip_address
|
||||
self.user_agent = user_agent
|
||||
self.active = active
|
||||
self.created_at = datetime.now()
|
||||
|
||||
|
||||
class logs (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Logs (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Log table
|
||||
Joins with user
|
||||
|
@ -140,15 +115,8 @@ class logs (base): # pylint: disable=too-few-public-methods, C0103
|
|||
msg = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, user_id, ip_address, code, msg):
|
||||
self.user_id = user_id
|
||||
self.ip_address = ip_address
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
self.created_at = datetime.now()
|
||||
|
||||
|
||||
class bans (base): # pylint: disable=too-few-public-methods, C0103
|
||||
class Bans (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Bans table
|
||||
"""
|
||||
|
@ -160,11 +128,5 @@ class bans (base): # pylint: disable=too-few-public-methods, C0103
|
|||
msg = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, ip_address, code, msg):
|
||||
self.ip_address = ip_address
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
self.created_at = datetime.now()
|
||||
|
||||
|
||||
base.metadata.create_all(engine)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue