class FileRefference(db.Model): __tablename__ = 'file_refference' id = db.Column(db.Integer, primary_key=True) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) post = db.relationship('Post', back_populates='files') filetracker_id = db.Column(db.Integer, db.ForeignKey('filetracker.id')) filetracker = db.relationship('FileTracker')
class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False, index=True) used_count = db.Column(db.Integer, nullable=False) # How many files use this tag user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False, index=True) files = db.relationship("File", secondary=association_file_tag) user = db.relationship("User")
class Board(db.Model): __tablename__ = 'board' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(32), nullable=False) short = db.Column(db.String(32), nullable=False) posts = db.relationship('Post', back_populates='board') files = db.relationship('FileTracker') def __repr__(self): return "<Board %s>" % self.id def dump_to_dict(self, with_posts=False, threads_only=True): dumped = { 'id': self.id, 'title': self.title, 'short': self.short } if with_posts: posts = list(filter( lambda post: # 1 -- is GENESIS_POST_ID... not(threads_only and (not post.parent or post.parent.id == 1)), self.posts )) posts = list(map( lambda post : post.dump_to_dict() )) dumped.update({ 'posts': posts }) return dumped
class Permission(db.Model): __tablename__ = 'permission' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', back_populates='permissions') board_id = db.Column(db.Integer, db.ForeignKey('board.id')) board = db.relationship('Board') def __repr__(self): return "<Permission %s>" % self.id
class Flight(db.Model): flight_number = db.Column(db.Integer, primary_key=True) flight_name = db.Column(db.String(length=80), nullable=False) scheduled_date = db.Column(db.String(length=10), nullable=False) scheduled_time = db.Column(db.String(length=10), nullable=False) expected_arrival_date = db.Column(db.String(length=10), nullable=False) expected_arrival_time = db.Column(db.String(length=10), nullable=False) departure = db.Column(db.String(length=80), nullable=False) destination = db.Column(db.String(length=80), nullable=False) fare_in_usd = db.Column(db.Integer, nullable=False) flight_duration = db.Column(db.String(length=10), nullable=False)
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(32), nullable=False) pass_hash = db.Column(db.String(32), nullable=False) registered = db.Column(db.DateTime, default=datetime.datetime.today(), nullable=False) permissions = db.relationship('Permission') sessions = db.relationship('Session') def __repr__(self): return "<User %s>" % self.id def dump_to_dict(self): return { 'id': self.id, 'login': self.login, 'registered': Utils.dump_time(self.registered) }
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(length=80), unique=True) password = db.Column(db.String(length=80)) email = db.Column(db.String(length=80), unique=True) created = db.Column(db.DateTime, default=datetime.utcnow) user_role = db.Column(db.String, default="user") def generate_auth_token(self, permission_level): if permission_level == 1: token = jwt.dumps({"email": self.email, "admin": 1}) return token elif permission_level == 2: token = jwt.dumps({"email": self.email, "admin": 2}) return token return jwt.dumps({"email": self.email, "admin": 0}) @staticmethod @auth.verify_token def verify_auth_token(token): g.user = None try: data = jwt.loads(token) except Exception as e: logger.exception(e) return False if "email" and "admin" in data: g.user = data["email"] g.admin = data["admin"] return True return False
class User(db.Model): id = db.Column(db.Integer, primary_key=True) admin = db.Column(db.Boolean, default=False) username = db.Column(db.String(32), nullable=False, unique=True) max_quota = db.Column(db.BigInteger, nullable=False) used_quota = db.Column(db.BigInteger, nullable=False) password_hash = db.Column(db.Binary(64), nullable=False) password_salt = db.Column(db.Binary(64), nullable=False) files = db.relationship("File") session_tokens = db.relationship("Session_token") tags = db.relationship("Tag")
class Session(db.Model): __tablename__ = 'session' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', back_populates='sessions') token = db.Column(db.String(32), default=Utils.rand_string_wrapper(24), nullable=False) opened = db.Column(db.DateTime, default=datetime.datetime.today(), nullable=False) ip = db.Column(db.String(32), default='0.0.0.0') user_agent = db.Column(db.String(32), nullable=False) def __repr__(self): return "<Session %s>" % self.id
class FileTracker(db.Model): __tablename__ = 'filetracker' id = db.Column(db.Integer, primary_key=True) file_path = db.Column(db.String(256)) preview_path = db.Column(db.String(256)) info = db.Column(db.String(256)) ext = db.Column(db.String(256)) uploaded = db.Column(db.DateTime, default=datetime.datetime.today(), nullable=False) board_id = db.Column(db.Integer, db.ForeignKey('board.id')) board = db.relationship('Board', back_populates='files') def dump_to_dict(self, full=False): return { 'id': self.id, 'file_path': self.file_path, 'preview_path': self.preview_path, 'info': self.info, 'ext': self.ext, 'uploaded': Utils.dump_time(self.uploaded) }
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) board_id = db.Column(db.Integer, db.ForeignKey('board.id')) board = db.relationship('Board', back_populates='posts') children = db.relationship('Post', back_populates='parent') parent_id = db.Column(db.Integer, db.ForeignKey('post.id')) parent = db.relationship('Post', remote_side=[id], back_populates='children') head = db.Column(db.String(256), nullable=False) body = db.Column(db.String(65536), nullable=False) created = db.Column(db.DateTime, default=datetime.datetime.today(), nullable=False) files = db.relationship('FileRefference') def dump_to_dict(self, with_children=False, with_files=True, child_number=None): dumped = { 'id': self.id, 'board_id': self.board_id, 'parent_id': self.parent_id, 'children_ids': list(map(lambda child : child.id, self.children)), 'head': self.head, 'body': parse_to_markup(self.body), 'created': Utils.dump_time(self.created) } if with_children: children = Utils.get_children(self)[:child_number] children = list(map( lambda post: post.dump_to_dict(), children )) dumped.update({ 'children': children }) if with_files: files = list(map( lambda file: file.filetracker.dump_to_dict(full=True), self.files )) dumped.update({ 'files': files }) return dumped
class File(db.Model): id = db.Column(db.Integer, primary_key=True) filename = db.Column(db.String(255), nullable=False, unique=True, index=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id"), index=True) user = db.relationship("User") tags = db.relationship("Tag", secondary=association_file_tag)
class Session_token(db.Model): id = db.Column(db.Integer, primary_key=True) session_token = db.Column(db.String(128), nullable=False, unique=True, index=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) user = db.relationship("User") last_access = db.Column(db.DateTime, default=datetime.utcnow())
from flask_sqlalchemy import SQLAlchemy from src.database.database import db from app import app from datetime import * association_file_tag = db.Table("association_file_tag", db.Column("tag_id", db.Integer, db.ForeignKey("tag.id"), primary_key=True), db.Column("file_id", db.Integer, db.ForeignKey("file.id"), primary_key=True) ) class User(db.Model): id = db.Column(db.Integer, primary_key=True) admin = db.Column(db.Boolean, default=False) username = db.Column(db.String(32), nullable=False, unique=True) max_quota = db.Column(db.BigInteger, nullable=False) used_quota = db.Column(db.BigInteger, nullable=False) password_hash = db.Column(db.Binary(64), nullable=False) password_salt = db.Column(db.Binary(64), nullable=False) files = db.relationship("File") session_tokens = db.relationship("Session_token") tags = db.relationship("Tag") class Session_token(db.Model): id = db.Column(db.Integer, primary_key=True) session_token = db.Column(db.String(128), nullable=False, unique=True, index=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) user = db.relationship("User") last_access = db.Column(db.DateTime, default=datetime.utcnow()) class File(db.Model): id = db.Column(db.Integer, primary_key=True)
class Blacklist(db.Model): id = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(length=255))