#84 Confirmation anti-nécropost

This commit is contained in:
Eragon 2021-01-12 16:40:52 +01:00
parent 63baae9683
commit c0ae3cc8ab
No known key found for this signature in database
GPG Key ID: 41F8C3FE5948FDAB
3 changed files with 22 additions and 13 deletions

View File

@ -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):
"""

View File

@ -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/<forum:f>/<topicpage:page>', 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)

View File

@ -19,6 +19,12 @@
{{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }}
{% if not last %}
<div class="bg-warn">
Ce topic est sans activité depuis plus de X jours, êtes-vous sûr de vouloir y poster ?
</div>
{% endif %}
{% if current_user.is_authenticated or V5Config.ENABLE_GUEST_POST %}
<div class=form>
<h3>Commenter le sujet</h3>