forked from rDrama/rDrama
whatever
parent
4467d52a19
commit
35ee7873a3
|
@ -47,7 +47,6 @@ class Comment(Base):
|
||||||
ban_reason = Column(String)
|
ban_reason = Column(String)
|
||||||
|
|
||||||
post = relationship("Submission", viewonly=True)
|
post = relationship("Submission", viewonly=True)
|
||||||
flags = relationship("CommentFlag", lazy="dynamic", viewonly=True)
|
|
||||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||||
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True)
|
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True)
|
||||||
parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
|
parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
|
||||||
|
@ -65,6 +64,11 @@ class Comment(Base):
|
||||||
|
|
||||||
return f"<Comment(id={self.id})>"
|
return f"<Comment(id={self.id})>"
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def flags(self):
|
||||||
|
return g.db.query(CommentFlag).options(lazyload('*')).filter_by(comment_id=self.id)
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def poll_voted(self, v):
|
def poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
|
|
|
@ -6,12 +6,14 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, deferred
|
from sqlalchemy.orm import relationship, deferred, lazyload
|
||||||
|
|
||||||
from files.__main__ import Base
|
from files.__main__ import Base
|
||||||
from files.helpers.const import AUTOPOLLER_ACCOUNT, censor_slurs, TROLLTITLES
|
from files.helpers.const import AUTOPOLLER_ACCOUNT, censor_slurs, TROLLTITLES
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from .flags import Flag
|
from .flags import Flag
|
||||||
|
from .comment import Comment
|
||||||
|
from flask import g
|
||||||
|
|
||||||
site = environ.get("DOMAIN").strip()
|
site = environ.get("DOMAIN").strip()
|
||||||
site_name = environ.get("SITE_NAME").strip()
|
site_name = environ.get("SITE_NAME").strip()
|
||||||
|
@ -51,8 +53,6 @@ class Submission(Base):
|
||||||
ban_reason = Column(String)
|
ban_reason = Column(String)
|
||||||
embed_url = Column(String)
|
embed_url = Column(String)
|
||||||
|
|
||||||
comments = relationship("Comment", lazy="dynamic", primaryjoin="Comment.parent_submission==Submission.id", viewonly=True)
|
|
||||||
flags = relationship("Flag", lazy="dynamic", viewonly=True)
|
|
||||||
author = relationship("User", primaryjoin="Submission.author_id==User.id")
|
author = relationship("User", primaryjoin="Submission.author_id==User.id")
|
||||||
oauth_app = relationship("OauthApp", viewonly=True)
|
oauth_app = relationship("OauthApp", viewonly=True)
|
||||||
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
|
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
|
||||||
|
@ -73,10 +73,15 @@ class Submission(Base):
|
||||||
return f"<Submission(id={self.id})>"
|
return f"<Submission(id={self.id})>"
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def flags(self):
|
||||||
|
return g.db.query(Flag).options(lazyload('*')).filter_by(post_id=self.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def options(self):
|
def options(self):
|
||||||
return self.comments.filter_by(author_id = AUTOPOLLER_ACCOUNT, level=1)
|
return g.db.query(Comment).options(lazyload('*')).filter_by(parent_submission = self.id, author_id = AUTOPOLLER_ACCOUNT, level=1)
|
||||||
|
|
||||||
def total_poll_voted(self, v):
|
def total_poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
|
|
|
@ -112,18 +112,15 @@ class User(Base):
|
||||||
original_username = deferred(Column(String))
|
original_username = deferred(Column(String))
|
||||||
referred_by = Column(Integer, ForeignKey("users.id"))
|
referred_by = Column(Integer, ForeignKey("users.id"))
|
||||||
|
|
||||||
submissions = relationship("Submission", lazy="dynamic", primaryjoin="Submission.author_id==User.id", viewonly=True)
|
badges = relationship("Badge", viewonly=True)
|
||||||
badges = relationship("Badge", lazy="dynamic", viewonly=True)
|
|
||||||
notifications = relationship("Notification", lazy="dynamic", viewonly=True)
|
|
||||||
subscriptions = relationship("Subscription", viewonly=True)
|
subscriptions = relationship("Subscription", viewonly=True)
|
||||||
following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True)
|
following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True)
|
||||||
followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True)
|
followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True)
|
||||||
viewers = relationship("ViewerRelationship", primaryjoin="User.id == ViewerRelationship.user_id", viewonly=True)
|
viewers = relationship("ViewerRelationship", primaryjoin="User.id == ViewerRelationship.user_id", viewonly=True)
|
||||||
blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id", viewonly=True)
|
blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id", viewonly=True)
|
||||||
blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id", viewonly=True)
|
blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id", viewonly=True)
|
||||||
apps = relationship("OauthApp", lazy="dynamic", viewonly=True)
|
authorizations = relationship("ClientAuth", viewonly=True)
|
||||||
authorizations = relationship("ClientAuth", lazy="dynamic", viewonly=True)
|
awards = relationship("AwardRelationship", primaryjoin="User.id==AwardRelationship.user_id", viewonly=True)
|
||||||
awards = relationship("AwardRelationship", lazy="dynamic", primaryjoin="User.id==AwardRelationship.user_id", viewonly=True)
|
|
||||||
referrals = relationship("User", viewonly=True)
|
referrals = relationship("User", viewonly=True)
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
@ -137,6 +134,11 @@ class User(Base):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def notifications(self):
|
||||||
|
return g.db.query(Notification).options(lazyload('*')).filter_by(user_id=self.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def created_date(self):
|
def created_date(self):
|
||||||
|
@ -145,11 +147,11 @@ class User(Base):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def user_awards(v):
|
def user_awards(self):
|
||||||
|
|
||||||
return_value = list(AWARDS2.values())
|
return_value = list(AWARDS2.values())
|
||||||
|
|
||||||
user_awards = v.awards
|
user_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter_by(user_id=self.id)
|
||||||
|
|
||||||
for val in return_value: val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count()
|
for val in return_value: val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count()
|
||||||
|
|
||||||
|
@ -475,7 +477,7 @@ class User(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def applications(self):
|
def applications(self):
|
||||||
return [x for x in self.apps.order_by(OauthApp.id.asc()).all()]
|
return g.db.query(OauthApp).options(lazyload('*')).filter_by(author_id=self.id).order_by(OauthApp.id.asc()).all()
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def subscribed_idlist(self, page=1):
|
def subscribed_idlist(self, page=1):
|
||||||
|
|
|
@ -929,7 +929,7 @@ def submit_post(v):
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
v.post_count = v.submissions.filter_by(is_banned=False, deleted_utc=0).count()
|
v.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0).count()
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
|
|
||||||
<h2 class="h5">Your Authorized Applications</h2>
|
<h2 class="h5">Your Authorized Applications</h2>
|
||||||
|
|
||||||
{% for auth in v.authorizations.all() %}
|
{% for auth in v.authorizations %}
|
||||||
|
|
||||||
<div id="auth-{{auth.id}}" class="settings-section rounded">
|
<div id="auth-{{auth.id}}" class="settings-section rounded">
|
||||||
<div class="d-lg-flex">
|
<div class="d-lg-flex">
|
||||||
|
|
Loading…
Reference in New Issue