2022-05-04 23:09:46 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
client_id = Column(String)
|
|
|
|
app_name = Column(String)
|
|
|
|
redirect_uri = Column(String)
|
|
|
|
description = Column(String)
|
|
|
|
author_id = Column(Integer, ForeignKey("users.id"))
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-18 00:46:46 +00:00
|
|
|
author = relationship("User", back_populates="apps")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return f"<OauthApp(id={self.id})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2022-07-02 06:48:04 +00:00
|
|
|
def permalink(self):
|
2022-10-10 05:22:18 +00:00
|
|
|
return f"{SITE_FULL}/admin/app/{self.id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@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)
|
|
|
|
|
2022-06-22 19:50:20 +00:00
|
|
|
posts=posts.order_by(Comment.id.desc())
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
posts=posts.offset(100*(page-1)).limit(101)
|
|
|
|
|
|
|
|
return [x[0] for x in posts.all()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClientAuth(Base):
|
|
|
|
|
|
|
|
__tablename__ = "client_auths"
|
|
|
|
|
|
|
|
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)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-09-12 10:19:35 +00:00
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
user = relationship("User")
|
|
|
|
application = relationship("OauthApp")
|
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-09-29 05:43:29 +00:00
|
|
|
return f"<ClientAuth(user_id={self.user_id}, oauth_client={self.oauth_client})>"
|