move pinned comment ordering to SQLAlchemy
parent
666b146daf
commit
be8be13a01
|
@ -155,13 +155,13 @@ def post_id(pid, anything=None, v=None, sub=None):
|
||||||
# shadowban check is done in sort_objects
|
# shadowban check is done in sort_objects
|
||||||
# output is needed: see comments.py
|
# output is needed: see comments.py
|
||||||
comments, output = get_comments_v_properties(v, True, None, Comment.parent_submission == post.id, Comment.level < 10)
|
comments, output = get_comments_v_properties(v, True, None, Comment.parent_submission == post.id, Comment.level < 10)
|
||||||
pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()]
|
pinned = [c[0] for c in comments.filter(Comment.stickied != None).order_by(Comment.created_utc.desc()).all()]
|
||||||
comments = comments.filter(Comment.level == 1, Comment.stickied == None)
|
comments = comments.filter(Comment.level == 1, Comment.stickied == None)
|
||||||
comments = sort_objects(sort, comments, Comment,
|
comments = sort_objects(sort, comments, Comment,
|
||||||
include_shadowbanned=(v and v.can_see_shadowbanned))
|
include_shadowbanned=(v and v.can_see_shadowbanned))
|
||||||
comments = [c[0] for c in comments.all()]
|
comments = [c[0] for c in comments.all()]
|
||||||
else:
|
else:
|
||||||
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all()
|
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).order_by(Comment.created_utc.desc()).all()
|
||||||
|
|
||||||
comments = g.db.query(Comment).filter(
|
comments = g.db.query(Comment).filter(
|
||||||
Comment.parent_submission == post.id,
|
Comment.parent_submission == post.id,
|
||||||
|
@ -199,22 +199,20 @@ def post_id(pid, anything=None, v=None, sub=None):
|
||||||
else: offset = 1
|
else: offset = 1
|
||||||
comments = comments2
|
comments = comments2
|
||||||
|
|
||||||
pinned2 = set()
|
pinned2 = {}
|
||||||
for pin in pinned:
|
for pin in pinned:
|
||||||
if pin.stickied_utc and int(time.time()) > pin.stickied_utc:
|
if pin.stickied_utc and int(time.time()) > pin.stickied_utc:
|
||||||
pin.stickied = None
|
pin.stickied = None
|
||||||
pin.stickied_utc = None
|
pin.stickied_utc = None
|
||||||
g.db.add(pin)
|
g.db.add(pin)
|
||||||
elif pin.level > 1:
|
elif pin.level > 1:
|
||||||
pinned2.add(pin.top_comment(g.db))
|
pinned2[pin.top_comment(g.db)] = ''
|
||||||
if pin.top_comment(g.db) in comments:
|
if pin.top_comment(g.db) in comments:
|
||||||
comments.remove(pin.top_comment(g.db))
|
comments.remove(pin.top_comment(g.db))
|
||||||
else:
|
else:
|
||||||
pinned2.add(pin)
|
pinned2[pin] = ''
|
||||||
|
|
||||||
pinned = list(pinned2)
|
post.replies = list(pinned2.keys()) + comments
|
||||||
pinned.sort(key=lambda x: x.created_utc, reverse=True)
|
|
||||||
post.replies = pinned + comments
|
|
||||||
|
|
||||||
post.views += 1
|
post.views += 1
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
|
|
Loading…
Reference in New Issue