forked from MarseyWorld/MarseyWorld
refactor pinning child comments
parent
6b6a3163a5
commit
17fd089870
|
@ -69,8 +69,9 @@ class Comment(Base):
|
|||
post = relationship("Submission", back_populates="comments")
|
||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto")
|
||||
top_comment = relationship("Comment", primaryjoin="Comment.id==Comment.top_comment_id")
|
||||
parent_comment = relationship("Comment", remote_side=[id], back_populates="child_comments")
|
||||
child_comments = relationship("Comment", order_by="Comment.realupvotes.desc()", remote_side=[parent_comment_id], back_populates="parent_comment")
|
||||
child_comments = relationship("Comment", order_by="Comment.stickied, Comment.realupvotes.desc()", remote_side=[parent_comment_id], back_populates="parent_comment")
|
||||
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment")
|
||||
flags = relationship("CommentFlag", order_by="CommentFlag.created_utc")
|
||||
options = relationship("CommentOption", order_by="CommentOption.id")
|
||||
|
|
|
@ -172,6 +172,11 @@ def post_id(pid, anything=None, v=None, sub=None):
|
|||
|
||||
pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()]
|
||||
|
||||
for x in pinned:
|
||||
if x.level > 1:
|
||||
pinned.remove(x)
|
||||
pinned.append(x.top_comment)
|
||||
|
||||
comments = comments.filter(Comment.level == 1, Comment.stickied == None)
|
||||
|
||||
comments = sort_comments(sort, comments)
|
||||
|
@ -182,6 +187,11 @@ def post_id(pid, anything=None, v=None, sub=None):
|
|||
else:
|
||||
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all()
|
||||
|
||||
for x in pinned:
|
||||
if x.level > 1:
|
||||
pinned.remove(x)
|
||||
pinned.append(x.top_comment)
|
||||
|
||||
comments = g.db.query(Comment).join(Comment.author).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.level == 1, Comment.stickied == None)
|
||||
|
||||
comments = sort_comments(sort, comments)
|
||||
|
|
Loading…
Reference in New Issue