2021-07-21 01:12:26 +00:00
|
|
|
from flask import *
|
|
|
|
from sqlalchemy import *
|
|
|
|
from sqlalchemy.orm import relationship, lazyload
|
|
|
|
from .submission import Submission
|
|
|
|
from .comment import Comment
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.__main__ import Base
|
2021-09-19 18:25:40 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2021-09-19 18:28:31 +00:00
|
|
|
import time
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 18:22:57 +00:00
|
|
|
class OauthApp(Base):
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
__tablename__ = "oauth_apps"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2021-10-06 22:38:15 +00:00
|
|
|
client_id = Column(String)
|
|
|
|
app_name = Column(String)
|
|
|
|
redirect_uri = Column(String)
|
|
|
|
description = Column(String)
|
2021-08-03 17:46:45 +00:00
|
|
|
author_id = Column(Integer, ForeignKey("users.id"))
|
2021-09-22 14:51:36 +00:00
|
|
|
author = relationship("User", viewonly=True)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-03 17:43:30 +00:00
|
|
|
def __repr__(self): return f"<OauthApp(id={self.id})>"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 18:22:57 +00:00
|
|
|
|
|
|
|
@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)))
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
@property
|
2021-09-19 18:25:40 +00:00
|
|
|
@lazy
|
2021-08-03 17:43:30 +00:00
|
|
|
def permalink(self): return f"/admin/app/{self.id}"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 20:06:52 +00:00
|
|
|
@lazy
|
2021-10-02 11:34:37 +00:00
|
|
|
def idlist(self, page=1):
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(app_id=self.id)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
posts=posts.order_by(Submission.created_utc.desc())
|
|
|
|
|
|
|
|
posts=posts.offset(100*(page-1)).limit(101)
|
|
|
|
|
|
|
|
return [x[0] for x in posts.all()]
|
|
|
|
|
2021-09-19 20:06:52 +00:00
|
|
|
@lazy
|
2021-10-02 11:34:37 +00:00
|
|
|
def comments_idlist(self, page=1):
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
posts = g.db.query(Comment.id).options(lazyload('*')).filter_by(app_id=self.id)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
posts=posts.order_by(Comment.created_utc.desc())
|
|
|
|
|
|
|
|
posts=posts.offset(100*(page-1)).limit(101)
|
|
|
|
|
|
|
|
return [x[0] for x in posts.all()]
|
|
|
|
|
2021-09-19 18:25:40 +00:00
|
|
|
|
|
|
|
|
2021-09-19 18:22:57 +00:00
|
|
|
class ClientAuth(Base):
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
__tablename__ = "client_auths"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"))
|
2021-10-06 22:38:15 +00:00
|
|
|
access_token = Column(String)
|
2021-08-03 17:46:45 +00:00
|
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
2021-09-22 14:51:36 +00:00
|
|
|
user = relationship("User", viewonly=True)
|
|
|
|
application = relationship("OauthApp", viewonly=True)
|
2021-09-19 18:22:57 +00:00
|
|
|
|
|
|
|
@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)))
|