diff --git a/app/routes/__init__.py b/app/routes/__init__.py index bc74cf3..5791ce5 100644 --- a/app/routes/__init__.py +++ b/app/routes/__init__.py @@ -6,7 +6,7 @@ from app.routes.admin import index, groups, account, forums, \ attachments, config, members, polls, login_as from app.routes.forum import index, topic from app.routes.polls import vote, delete -from app.routes.posts import edit +from app.routes.posts import edit, redirect from app.routes.programs import index, submit, program from app.routes.api import markdown diff --git a/app/routes/posts/redirect.py b/app/routes/posts/redirect.py new file mode 100644 index 0000000..ea5edb7 --- /dev/null +++ b/app/routes/posts/redirect.py @@ -0,0 +1,39 @@ +from app import app, db +from app.models.attachment import Attachment +from app.models.comment import Comment +from app.models.forum import Forum +from app.models.post import Post +from app.models.program import Program +from app.models.thread import Thread +from app.models.topic import Topic +from app.models.user import Member +from app.utils.render import render +from app.utils.check_csrf import check_csrf +from app.utils.priv_required import priv_required +from app.forms.forum import CommentEditForm, AnonymousCommentEditForm, TopicEditForm +from app.forms.post import MovePost, SearchThread +from wtforms import BooleanField +from urllib.parse import urlparse +from flask import redirect, url_for, abort, request, flash +from flask_login import login_required, current_user +from sqlalchemy import text + + +@app.route('/post/', methods=['GET', 'POST']) +def redirect_post(postid): + print(postid) + c = Comment.query.filter_by(id=postid).first_or_404() + + owner = c.thread.owner_post + + if hasattr(owner, 'forum'): + # 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)) + else: + # Is a program + url = url_for('program_view', page=owner.name) + + return redirect(url, 301) diff --git a/app/templates/search.html b/app/templates/search.html index 1687766..0d26d77 100644 --- a/app/templates/search.html +++ b/app/templates/search.html @@ -36,9 +36,11 @@ 'sortBy': request.args.get('sortBy')}) }} {% for i in results.items %}
- {{ i.id }} {{ i.title }} {{ i.forum }}
+ {{ i.id }} {{ i.title }}
{% if i.forum %} {{ i.title }} + {% elif i.thread %} + {{ i.thread.owner_topic[0].title }} {% endif %} {{ i.headline }}