mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Submitted to PyLints needs :3
This commit is contained in:
parent
4cfcd178f1
commit
7ed3b455dd
12 changed files with 509 additions and 460 deletions
113
gallery/db.py
113
gallery/db.py
|
@ -1,6 +1,10 @@
|
|||
"""
|
||||
OnlyLegs - Database
|
||||
Database models and functions for SQLAlchemy
|
||||
"""
|
||||
import os
|
||||
import platformdirs
|
||||
from datetime import datetime
|
||||
import platformdirs
|
||||
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import declarative_base, relationship
|
||||
|
@ -11,7 +15,11 @@ engine = create_engine(f'sqlite:///{path_to_db}', echo=False)
|
|||
base = declarative_base()
|
||||
|
||||
|
||||
class users (base):
|
||||
class users (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
User table
|
||||
Joins with post, groups, session and log
|
||||
"""
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
@ -19,7 +27,7 @@ class users (base):
|
|||
email = Column(String, unique=True, nullable=False)
|
||||
password = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
|
||||
posts = relationship('posts')
|
||||
groups = relationship('groups')
|
||||
session = relationship('sessions')
|
||||
|
@ -30,19 +38,24 @@ class users (base):
|
|||
self.email = email
|
||||
self.password = password
|
||||
self.created_at = datetime.now()
|
||||
|
||||
class posts (base):
|
||||
|
||||
|
||||
class posts (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Post table
|
||||
Joins with group_junction
|
||||
"""
|
||||
__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)
|
||||
|
||||
|
||||
junction = relationship('group_junction')
|
||||
|
||||
|
||||
def __init__(self, file_name, description, alt, author_id):
|
||||
self.file_name = file_name
|
||||
self.description = description
|
||||
|
@ -50,84 +63,108 @@ class posts (base):
|
|||
self.author_id = author_id
|
||||
self.created_at = datetime.now()
|
||||
|
||||
class groups (base):
|
||||
|
||||
class groups (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Group table
|
||||
Joins with group_junction
|
||||
"""
|
||||
__tablename__ = 'groups'
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String, nullable=False)
|
||||
description = Column(String, nullable=False)
|
||||
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()
|
||||
|
||||
class group_junction (base):
|
||||
|
||||
|
||||
class group_junction (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Junction table for posts and groups
|
||||
Joins with posts and groups
|
||||
"""
|
||||
__tablename__ = 'group_junction'
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
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):
|
||||
|
||||
|
||||
class sessions (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Session table
|
||||
Joins with user
|
||||
"""
|
||||
__tablename__ = 'sessions'
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey('users.id'))
|
||||
session_uuid = Column(String, nullable=False)
|
||||
ip = Column(String, nullable=False)
|
||||
ip_address = Column(String, nullable=False)
|
||||
user_agent = Column(String, nullable=False)
|
||||
active = Column(Boolean, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, user_id, session_uuid, ip, user_agent, active):
|
||||
|
||||
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 = ip
|
||||
self.ip_address = ip_address
|
||||
self.user_agent = user_agent
|
||||
self.active = active
|
||||
self.created_at = datetime.now()
|
||||
|
||||
class logs (base):
|
||||
|
||||
|
||||
class logs (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Log table
|
||||
Joins with user
|
||||
"""
|
||||
__tablename__ = 'logs'
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey('users.id'))
|
||||
ip = Column(String, nullable=False)
|
||||
ip_address = Column(String, nullable=False)
|
||||
code = Column(Integer, nullable=False)
|
||||
msg = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, user_id, ip, code, msg):
|
||||
|
||||
def __init__(self, user_id, ip_address, code, msg):
|
||||
self.user_id = user_id
|
||||
self.ip = ip
|
||||
self.ip_address = ip_address
|
||||
self.code = code
|
||||
self.msg = msg
|
||||
self.created_at = datetime.now()
|
||||
|
||||
class bans (base):
|
||||
|
||||
|
||||
class bans (base): # pylint: disable=too-few-public-methods, C0103
|
||||
"""
|
||||
Bans table
|
||||
"""
|
||||
__tablename__ = 'bans'
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
ip = Column(String, nullable=False)
|
||||
ip_address = Column(String, nullable=False)
|
||||
code = Column(Integer, nullable=False)
|
||||
msg = Column(String, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
def __init__(self, ip, code, msg):
|
||||
self.ip = ip
|
||||
|
||||
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)
|
||||
base.metadata.create_all(engine)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue