search: Fix links for comments

This commit is contained in:
Eragon 2023-09-05 21:09:54 +02:00
parent a039d1b500
commit da037f677e
Signed by: Eragon
GPG Key ID: 087126EBFC725006
1 changed files with 10 additions and 7 deletions

View File

@ -21,17 +21,20 @@ from sqlalchemy import text
@app.route('/post/<int:postid>', methods=['GET', 'POST'])
def redirect_post(postid):
print(postid)
c = Comment.query.filter_by(id=postid).first_or_404()
c = Comment.query.get_or_404(postid)
owner = c.thread.owner_post
if hasattr(owner, 'forum'):
if owner.type == 'topic':
# Is a topic
comments = owner.thread.comments.order_by(Comment.date_created.asc()).where(
Comment.date_created >= c.date_created
).paginate(0, Thread.COMMENTS_PER_PAGE, True)
url = url_for('forum_topic', f=owner.forum, page=(owner, comments.pages))
print('topic')
comments = Comment.query.where(
Comment.thread_id == c.thread.id,
Comment.date_created <= c.date_created
).order_by(
Comment.date_created.asc()
).paginate(per_page=Thread.COMMENTS_PER_PAGE, error_out=False)
url = url_for('forum_topic', f=owner.forum, page=(owner, comments.pages), _anchor=str(c.id))
else:
# Is a program
url = url_for('program_view', page=owner.name)