From c0ae3cc8ab74cc213b582ebd07a08beea4029181 Mon Sep 17 00:00:00 2001 From: Eragon Date: Tue, 12 Jan 2021 16:40:52 +0100 Subject: [PATCH] =?UTF-8?q?#84=20Confirmation=20anti-n=C3=A9cropost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/comment.py | 7 ++++--- app/routes/forum/topic.py | 22 ++++++++++++---------- app/templates/forum/topic.html | 6 ++++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/models/comment.py b/app/models/comment.py index 8c7be13..8343e79 100644 --- a/app/models/comment.py +++ b/app/models/comment.py @@ -2,6 +2,7 @@ from app import db from app.models.post import Post from sqlalchemy.orm import backref + class Comment(Post): __tablename__ = 'comment' __mapper_args__ = {'polymorphic_identity': __tablename__} @@ -14,10 +15,10 @@ class Comment(Post): # Parent thread thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'), - nullable=False) + nullable=False) thread = db.relationship('Thread', - backref=backref('comments', lazy='dynamic'), - foreign_keys=thread_id) + backref=backref('comments', lazy='dynamic'), + foreign_keys=thread_id) def __init__(self, author, text, thread): """ diff --git a/app/routes/forum/topic.py b/app/routes/forum/topic.py index 173e066..2af6b3b 100644 --- a/app/routes/forum/topic.py +++ b/app/routes/forum/topic.py @@ -1,17 +1,17 @@ from flask_login import current_user -from flask import request, redirect, url_for, flash, abort +from flask import 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, AnonymousCommentForm -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.user import Guest from app.models.attachment import Attachment +import datetime + @app.route('/forum//', methods=['GET', 'POST']) def forum_topic(f, page): @@ -27,7 +27,7 @@ def forum_topic(f, page): form = AnonymousCommentForm() if form.validate_on_submit() and \ - (V5Config.ENABLE_GUEST_POST or current_user.is_authenticated): + (V5Config.ENABLE_GUEST_POST or current_user.is_authenticated): # Manage author if current_user.is_authenticated: author = current_user @@ -58,8 +58,8 @@ def forum_topic(f, page): flash('Message envoyé', 'ok') # Redirect to empty the form - return redirect(url_for('forum_topic', f=f, page=(t,"fin"), - _anchor=c.id)) + return redirect(url_for('forum_topic', f=f, page=(t, "fin"), + _anchor=c.id)) # Update views t.views += 1 @@ -67,10 +67,12 @@ def forum_topic(f, page): db.session.commit() if page == -1: - page = (t.thread.comments.count() - 1) \ - // Thread.COMMENTS_PER_PAGE + 1 + page = (t.thread.comments.count() - 1) // Thread.COMMENTS_PER_PAGE + 1 comments = t.thread.comments.paginate(page, - Thread.COMMENTS_PER_PAGE, True) + Thread.COMMENTS_PER_PAGE, True) - return render('/forum/topic.html', t=t, form=form, comments=comments) + now_minus = datetime.datetime.now() - datetime.timedelta(minutes=15) + last_edited_comment = t.thread.comments.filter(Comment.date_modified >= now_minus).first() + + return render('/forum/topic.html', t=t, form=form, comments=comments, last=last_edited_comment) diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 3c48fda..99b454a 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -19,6 +19,12 @@ {{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }} + {% if not last %} +
+ Ce topic est sans activité depuis plus de X jours, êtes-vous sûr de vouloir y poster ? +
+ {% endif %} + {% if current_user.is_authenticated or V5Config.ENABLE_GUEST_POST %}

Commenter le sujet