from app import app, db from app.forms.login import LoginForm from app.forms.search import SearchForm from app.models.forum import Forum from app.models.topic import Topic from app.models.thread import Thread from app.models.comment import Comment from app.models.users import Member @app.context_processor def menu_processor(): """ All items used to render main menu. Includes search form """ login_form = LoginForm(prefix="menu_") search_form = SearchForm() main_forum = Forum.query.filter_by(parent=None).first() # Constructing last forum comments [(member, topic)] raw = db.session.execute( """SELECT member.id, topic.id FROM comment RIGHT JOIN post ON comment.id = post.id INNER JOIN topic ON comment.thread_id = topic.thread_id INNER JOIN member ON post.author_id = member.id ORDER BY post.date_created DESC LIMIT 10""") last_forum_comments = [(Member.query.get(m), Topic.query.get(t)) for m, t in raw] return dict(login_form=login_form, search_form=search_form, main_forum=main_forum, last_forum_comments=last_forum_comments)