search: Add links for programs and programs comments

This commit is contained in:
Eragon 2023-09-26 21:18:58 +02:00
parent fee66d22bd
commit 4ba7c10786
Signed by: Eragon
GPG Key ID: 087126EBFC725006
2 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,7 @@
from app import app
from app.models.comment import Comment
from app.models.thread import Thread
from app.models.program import Program
from flask import redirect, url_for
@ -10,17 +11,19 @@ def redirect_post(postid):
owner = c.thread.owner_post
# Get the comments for the thread
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)
if owner.type == 'topic':
# Is a 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)
url = url_for('program_view', page=(owner, comments.pages), _anchor=str(c.id))
return redirect(url, 301)

View File

@ -54,7 +54,13 @@
{% if i.forum %}
<a href="{{ url_for('forum_topic', f=i.forum, page=(i , 'fin')) }}">{{ i.title }}</a>
{% elif i.thread %}
{% if i.thread.owner_topic %}
{% if i.thread.owner_program %}
{% if i.thread.owner_program[0].id == i.id %}
<a href="{{ url_for('program_view', page=(i.thread.owner_program[0], '')) }}">{{ i.thread.owner_program[0].name }}</a>
{% else %}
<a href="{{ url_for('redirect_post', postid=i.id) }}">{{ i.thread.owner_program[0].name }}</a>
{% endif %}
{% elif i.thread.owner_topic %}
<a href="{{ url_for('redirect_post', postid=i.id) }}">{{ i.thread.owner_topic[0].title }}</a>
{% endif %}
{% endif %}