From cf61b43e179c410f7fa38fd0c609d5d980d476e1 Mon Sep 17 00:00:00 2001 From: Darks Date: Wed, 4 Dec 2019 13:58:48 +0100 Subject: [PATCH] Modification de la liste des topics actifs du menu + Correction de bugs --- app/models/users.py | 2 +- app/processors/menu.py | 19 +++++++++---------- app/routes/account/login.py | 1 + app/routes/forum/topic.py | 3 ++- app/templates/base/navbar/forum.html | 6 ++---- config.py | 2 -- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/models/users.py b/app/models/users.py index 66cb887..fa3e00e 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -203,7 +203,7 @@ class Member(User): Reward xp to a member. If [amount] is negative, the xp total of the member will decrease, down to zero. """ - self.xp_points = min(max(self.xp_points + amount, 0), 1000000000) + self.xp = min(max(self.xp + amount, 0), 1000000000) def set_password(self, password): """ diff --git a/app/processors/menu.py b/app/processors/menu.py index 9e226bf..eae5737 100644 --- a/app/processors/menu.py +++ b/app/processors/menu.py @@ -15,15 +15,14 @@ def menu_processor(): 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] + # Constructing last active topics + raw = db.session.execute( """SELECT topic.id FROM topic + INNER JOIN comment ON topic.thread_id = comment.thread_id + INNER JOIN post ON post.id = comment.id + GROUP BY topic.id + ORDER BY MAX(post.date_created) DESC + LIMIT 10;""") + last_active_topics = [Topic.query.get(id) for id in raw] return dict(login_form=login_form, search_form=search_form, - main_forum=main_forum, last_forum_comments=last_forum_comments) + main_forum=main_forum, last_active_topics=last_active_topics) diff --git a/app/routes/account/login.py b/app/routes/account/login.py index 75fed09..257a06b 100644 --- a/app/routes/account/login.py +++ b/app/routes/account/login.py @@ -16,6 +16,7 @@ def login(): form = LoginForm() lateral = LoginForm(prefix="menu_") + if lateral.validate_on_submit(): form = lateral if form.validate_on_submit(): diff --git a/app/routes/forum/topic.py b/app/routes/forum/topic.py index aa4df91..aad3a10 100644 --- a/app/routes/forum/topic.py +++ b/app/routes/forum/topic.py @@ -1,13 +1,14 @@ from flask_login import current_user from flask import request, redirect, url_for, flash, abort +from app import app, db +from config import V5Config from app.utils.render import render from app.forms.forum import CommentForm 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 import app, db @app.route('/forum//', methods=['GET', 'POST']) diff --git a/app/templates/base/navbar/forum.html b/app/templates/base/navbar/forum.html index 128c850..09e11a3 100644 --- a/app/templates/base/navbar/forum.html +++ b/app/templates/base/navbar/forum.html @@ -15,12 +15,10 @@
-

Derniers commentaires

+

Derniers topics actifs

    - {% for m, t in last_forum_comments %} + {% for t in last_active_topics %}
  • - {{ m.name }} - sur {{ t.title }}
  • {% endfor %} diff --git a/config.py b/config.py index 892ccd5..40486d2 100644 --- a/config.py +++ b/config.py @@ -9,8 +9,6 @@ class Config(object): 'postgresql+psycopg2://' + os.environ.get('USER') + ':@/' + DB_NAME SQLALCHEMY_TRACK_MODIFICATIONS = False UPLOAD_FOLDER = './app/static/avatars' - SESSION_COOKIE_SECURE = True - REMEMBER_COOKIE_SECURE = True class V5Config(object):