forked from MarseyWorld/MarseyWorld
master
parent
15e7412016
commit
e512b15771
|
@ -86,6 +86,11 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
|
||||
return f"<Comment(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def score(self):
|
||||
return self.upvotes - self.downvotes
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def fullname(self):
|
||||
|
|
|
@ -100,6 +100,16 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
def __repr__(self):
|
||||
return f"<Submission(id={self.id})>"
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def comment_count(self):
|
||||
return len(self.comments)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def score(self):
|
||||
return self.upvotes - self.downvotes
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def hotscore(self):
|
||||
|
|
|
@ -116,8 +116,12 @@ class User(Base, Stndrd, Age_times):
|
|||
primaryjoin="User.id==AwardRelationship.user_id"
|
||||
)
|
||||
|
||||
# properties defined as SQL server-side functions
|
||||
referral_count = deferred(Column(Integer, server_default=FetchedValue()))
|
||||
referred_by = Column(Integer, ForeignKey("users.id"))
|
||||
|
||||
referrals = relationship(
|
||||
"User",
|
||||
lazy="joined"
|
||||
)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
|
@ -129,6 +133,11 @@ class User(Base, Stndrd, Age_times):
|
|||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def referral_count(self):
|
||||
return self.referrals.count()
|
||||
|
||||
def has_block(self, target):
|
||||
|
||||
return g.db.query(UserBlock).filter_by(
|
||||
|
@ -184,9 +193,9 @@ class User(Base, Stndrd, Age_times):
|
|||
elif sort == "controversial":
|
||||
submissions = sorted(submissions.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
submissions = submissions.order_by(Submission.score.desc()).all()
|
||||
submissions = sorted(submissions.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
submissions = submissions.order_by(Submission.score.asc()).all()
|
||||
submissions = sorted(submissions.all(), key=lambda x: x.score)
|
||||
elif sort == "comments":
|
||||
submissions = submissions.order_by(Submission.comment_count.desc()).all()
|
||||
|
||||
|
@ -227,9 +236,9 @@ class User(Base, Stndrd, Age_times):
|
|||
elif sort == "controversial":
|
||||
comments = sorted(comments.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
comments = comments.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score)
|
||||
|
||||
firstrange = 25 * (page - 1)
|
||||
secondrange = firstrange + 26
|
||||
|
|
|
@ -103,9 +103,9 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
)
|
||||
|
||||
if sort == "top":
|
||||
comments = comms.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comms.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score)
|
||||
elif sort == "new":
|
||||
comments = comms.order_by(Comment.created_utc.desc()).all()
|
||||
elif sort == "old":
|
||||
|
@ -133,9 +133,9 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
)
|
||||
|
||||
if sort == "top":
|
||||
output = comms.order_by(Comment.score.asc()).all()
|
||||
output = sorted(comms.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
output = comms.order_by(Comment.score.desc()).all()
|
||||
output = sorted(comms.all(), key=lambda x: x.score)
|
||||
elif sort == "new":
|
||||
output = comms.order_by(Comment.created_utc.desc()).all()
|
||||
elif sort == "old":
|
||||
|
|
|
@ -126,9 +126,9 @@ def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words=''
|
|||
elif sort == "controversial":
|
||||
posts = sorted(posts.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
posts = posts.order_by(Submission.score.desc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
posts = posts.order_by(Submission.score.asc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score)
|
||||
elif sort == "comments":
|
||||
posts = posts.order_by(Submission.comment_count.desc()).all()
|
||||
elif sort == "random":
|
||||
|
@ -270,9 +270,9 @@ def changeloglist(v=None, sort="new", page=1 ,t="all", **kwargs):
|
|||
elif sort == "controversial":
|
||||
posts = sorted(posts.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
posts = posts.order_by(Submission.score.desc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
posts = posts.order_by(Submission.score.asc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score)
|
||||
elif sort == "comments":
|
||||
posts = posts.order_by(Submission.comment_count.desc()).all()
|
||||
elif sort == "random":
|
||||
|
@ -380,9 +380,9 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", **kwargs):
|
|||
elif sort == "controversial":
|
||||
comments = sorted(comments.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
comments = comments.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score)
|
||||
|
||||
firstrange = 25 * (page - 1)
|
||||
secondrange = firstrange+100
|
||||
|
|
|
@ -106,9 +106,9 @@ def post_id(pid, anything=None, v=None):
|
|||
)
|
||||
|
||||
if sort == "top":
|
||||
comments = comms.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comms.all(), key=lambda x: x[0].score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comms.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comms.all(), key=lambda x: x[0].score)
|
||||
elif sort == "new":
|
||||
comments = comms.order_by(Comment.created_utc.desc()).all()
|
||||
elif sort == "old":
|
||||
|
@ -140,9 +140,9 @@ def post_id(pid, anything=None, v=None):
|
|||
)
|
||||
|
||||
if sort == "top":
|
||||
comments = comms.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comms.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comms.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comms.all(), key=lambda x: x.score)
|
||||
elif sort == "new":
|
||||
comments = comms.order_by(Comment.created_utc.desc()).all()
|
||||
elif sort == "old":
|
||||
|
|
|
@ -124,9 +124,9 @@ def searchlisting(criteria, v=None, page=1, t="None", sort="top", b=None):
|
|||
elif sort == "controversial":
|
||||
posts = sorted(posts.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
posts = posts.order_by(Submission.score.desc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
posts = posts.order_by(Submission.score.asc()).all()
|
||||
posts = sorted(posts.all(), key=lambda x: x.score)
|
||||
elif sort == "comments":
|
||||
posts = posts.order_by(Submission.comment_count.desc()).all()
|
||||
elif sort == "random":
|
||||
|
@ -185,9 +185,9 @@ def searchcommentlisting(criteria, v=None, page=1, t="None", sort="top"):
|
|||
elif sort == "controversial":
|
||||
comments = sorted(comments.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||
elif sort == "top":
|
||||
comments = comments.order_by(Comment.score.desc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score, reverse=True)
|
||||
elif sort == "bottom":
|
||||
comments = comments.order_by(Comment.score.asc()).all()
|
||||
comments = sorted(comments.all(), key=lambda x: x.score)
|
||||
|
||||
total = len(list(comments))
|
||||
firstrange = 25 * (page - 1)
|
||||
|
|
Loading…
Reference in New Issue