diff --git a/app/__init__.py b/app/__init__.py index 9bc5e67..2d20ff9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,7 +15,6 @@ login = LoginManager(app) login.login_view = 'login' login.login_message = "Veuillez vous authentifier avant de continuer." - from app.utils.converters import * app.url_map.converters['topicslug'] = TopicSlugConverter app.url_map.converters['forum'] = ForumConverter @@ -26,12 +25,9 @@ def request_time(): g.request_start_time = time.time() g.request_time = lambda: "%.5fs" % (time.time() - g.request_start_time) -@app.context_processor -def utilities_processor(): - return dict( - len=len, - enumerate=enumerate - ) + +from app.processors.menu import menu_processor +from app.processors.utilities import utilities_processor from app import models # IDK why this is here, but it works from app.models.comment import Comment diff --git a/app/processors/menu.py b/app/processors/menu.py new file mode 100644 index 0000000..9e226bf --- /dev/null +++ b/app/processors/menu.py @@ -0,0 +1,29 @@ +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) diff --git a/app/processors/utilities.py b/app/processors/utilities.py new file mode 100644 index 0000000..bc28c70 --- /dev/null +++ b/app/processors/utilities.py @@ -0,0 +1,9 @@ +from app import app + +@app.context_processor +def utilities_processor(): + """ Add some utilities to render context """ + return dict( + len=len, + enumerate=enumerate + ) diff --git a/app/routes/forum/index.py b/app/routes/forum/index.py index 88d9642..6ca1e19 100644 --- a/app/routes/forum/index.py +++ b/app/routes/forum/index.py @@ -11,8 +11,7 @@ from app import app, db @app.route('/forum/') def forum_index(): - main_forum = Forum.query.filter_by(parent=None).first() - return render('/forum/index.html', main_forum=main_forum) + return render('/forum/index.html') @app.route('/forum//', methods=['GET', 'POST']) def forum_page(f): diff --git a/app/routes/forum/topic.py b/app/routes/forum/topic.py index 5496ba4..0a4d67c 100644 --- a/app/routes/forum/topic.py +++ b/app/routes/forum/topic.py @@ -1,5 +1,5 @@ from flask_login import current_user -from flask import request, redirect, url_for, flash +from flask import request, redirect, url_for, flash, abort from app.utils.render import render from app.forms.forum import CommentForm @@ -12,6 +12,10 @@ from app import app, db @app.route('/forum//', methods=['GET', 'POST']) def forum_topic(f, t): + # Quick n' dirty workaround to converters + if f != t.forum: + abort(404) + form = CommentForm() if form.validate_on_submit(): diff --git a/app/templates/base/navbar/forum.html b/app/templates/base/navbar/forum.html index aab3e00..128c850 100644 --- a/app/templates/base/navbar/forum.html +++ b/app/templates/base/navbar/forum.html @@ -5,25 +5,24 @@ Forum - Index du forum + Index du forum
- Vie communautaire - Projets de programmation - Questions et problèmes - Discussions - Administration - CreativeCalc + {% for f in main_forum.sub_forums %} + {{ f.name }} + {% endfor %}

Derniers commentaires

diff --git a/app/utils/render.py b/app/utils/render.py index e86fd77..d846e3c 100644 --- a/app/utils/render.py +++ b/app/utils/render.py @@ -1,16 +1,16 @@ from flask import render_template from app.forms.login import LoginForm from app.forms.search import SearchForm +from app.models.forum import Forum - -def render(*args, styles=[], **kwargs): +def render(*args, styles=[], scripts=[], **kwargs): # TODO: debugguer cette merde : au logout, ça foire # if current_user.is_authenticated: # login_form = LoginForm() # return render_template(*args, **kwargs, login_form=login_form) # return render_template(*args, **kwargs) - # Pour jouer sur les feuilles de style : + # Pour jouer sur les feuilles de style ou les scripts : # render('page.html', styles=['-css/form.css', '+css/admin/forms.css']) styles_ = [ @@ -24,6 +24,10 @@ def render(*args, styles=[], **kwargs): 'css/responsive.css', 'css/table.css' ] + scripts_ = [ + + ] + for s in styles: print(s[1:]) if s[0] == '-': @@ -31,7 +35,11 @@ def render(*args, styles=[], **kwargs): if s[0] == '+': styles_.append(s[1:]) - login_form = LoginForm(prefix="menu_") - search_form = SearchForm() - return render_template(*args, **kwargs, - login_form=login_form, search_form=search_form, styles=styles_) + for s in scripts: + print(s[1:]) + if s[0] == '-': + scripts_.remove(s[1:]) + if s[0] == '+': + scripts_.append(s[1:]) + + return render_template(*args, **kwargs, styles=styles_, scripts=scripts_)