
* #39 Add Flask-Migrate dep * #39 Make it such that flask db init can run https://github.com/miguelgrinberg/Flask-Migrate/issues/196#issuecomment-381343393 * Run flask db init, update migrations.env, commit artifacts * Set up a script such that you can `docker-compose exec files bash -c 'cd /service; FLASK_APP="files/cli:app" flask '` and have it do whatever flask thing you want * Fix circular dependency * import * is evil * Initial alembic migration, has issues with constraints and nullable columns * Bring alts table up to date with alembic autogenerate * Rerun flask db revision autogenerate * Bring award_relationships table up to date with alembic autogenerate * [#39/alembic] files/classes/__init__.py is evil but is at least explicitly evil now * #39 fix model in files/classes/badges.py * #39 fix model in files/classes/domains.py and files/classes/clients.py * #39 fix models: comment saves, comment flags * #39 fix models: comments * Few more imports * #39 columns that are not nullable should be flagged as not nullable * #39 Add missing indexes to model defs * [#39] add missing unique constraints to model defs * [#39] Temporarily undo any model changes which cause the sqlalchemy model to be out of sync with the actual dump * #39 Deforeignkeyify the correct column to make alembic happy * #39 flask db revision --autogenerate now creates an empty migration * #39 Migration format such that files are listed in creation order * #39 Better first revision * #39 Revert the model changes that were required to get to zero differences between db revision --autogenerate and the existing schema * #39 The first real migration * #39 Ensure that foreign key constraints are named in migration * #39 Alembic migrations for FK constraints, column defs * [#39] Run DB migrations before starting tests * [#39] New test to ensure migrations are up to date * [#39] More descriptive test failure message * Add -T flag to docker-compose exec * [#39] Run alembic migrations when starting the container
90 lines
2.2 KiB
Python
90 lines
2.2 KiB
Python
from flask import *
|
|
from sqlalchemy import *
|
|
from sqlalchemy.orm import relationship
|
|
from .submission import Submission
|
|
from .comment import Comment
|
|
from files.__main__ import Base
|
|
from files.helpers.lazy import lazy
|
|
from files.helpers.const import *
|
|
import time
|
|
|
|
class OauthApp(Base):
|
|
|
|
__tablename__ = "oauth_apps"
|
|
__table_args__ = (
|
|
UniqueConstraint('client_id', name='unique_id'),
|
|
)
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
client_id = Column(String)
|
|
app_name = Column(String(length=50), nullable=False)
|
|
redirect_uri = Column(String(length=50), nullable=False)
|
|
description = Column(String(length=256), nullable=False)
|
|
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
author = relationship("User", viewonly=True)
|
|
|
|
def __repr__(self): return f"<OauthApp(id={self.id})>"
|
|
|
|
|
|
@property
|
|
@lazy
|
|
def created_date(self):
|
|
return time.strftime("%d %B %Y", time.gmtime(self.created_utc))
|
|
|
|
@property
|
|
@lazy
|
|
def created_datetime(self):
|
|
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
|
|
|
|
@property
|
|
@lazy
|
|
def permalink(self): return f"/admin/app/{self.id}"
|
|
|
|
@lazy
|
|
def idlist(self, page=1):
|
|
|
|
posts = g.db.query(Submission.id).filter_by(app_id=self.id)
|
|
|
|
posts=posts.order_by(Submission.created_utc.desc())
|
|
|
|
posts=posts.offset(100*(page-1)).limit(101)
|
|
|
|
return [x[0] for x in posts.all()]
|
|
|
|
@lazy
|
|
def comments_idlist(self, page=1):
|
|
|
|
posts = g.db.query(Comment.id).filter_by(app_id=self.id)
|
|
|
|
posts=posts.order_by(Comment.created_utc.desc())
|
|
|
|
posts=posts.offset(100*(page-1)).limit(101)
|
|
|
|
return [x[0] for x in posts.all()]
|
|
|
|
|
|
|
|
class ClientAuth(Base):
|
|
|
|
__tablename__ = "client_auths"
|
|
__table_args__ = (
|
|
UniqueConstraint('access_token', name='unique_access'),
|
|
)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
|
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"), primary_key=True)
|
|
access_token = Column(String, nullable=False)
|
|
|
|
user = relationship("User", viewonly=True)
|
|
application = relationship("OauthApp", viewonly=True)
|
|
|
|
@property
|
|
@lazy
|
|
def created_date(self):
|
|
return time.strftime("%d %B %Y", time.gmtime(self.created_utc))
|
|
|
|
@property
|
|
@lazy
|
|
def created_datetime(self):
|
|
return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc)))
|