forum: fix #84

This commit is contained in:
Eldeberen 2021-02-21 20:17:48 +01:00
parent f3bb8858f0
commit f10d5404c2
Signed by untrusted user: Darks
GPG Key ID: 7515644268BE1433
3 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,6 @@
from flask_login import current_user
from flask import redirect, url_for, flash, abort
from sqlalchemy import desc
from app import app, db
from config import V5Config
@ -10,7 +11,7 @@ from app.models.comment import Comment
from app.models.user import Guest
from app.models.attachment import Attachment
import datetime
from datetime import datetime
@app.route('/forum/<forum:f>/<topicpage:page>', methods=['GET', 'POST'])
@ -59,7 +60,7 @@ 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))
_anchor=c.id))
# Update views
t.views += 1
@ -70,9 +71,12 @@ def forum_topic(f, page):
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)
now_minus = datetime.datetime.now() - datetime.timedelta(days=V5Config.NECROPOST_LIMIT)
last_updated_comment = t.thread.comments.filter(Comment.date_modified <= now_minus).first()
# Anti-necropost
last_com = t.thread.comments.order_by(desc(Comment.date_modified)).first()
inactive = datetime.now() - last_com.date_modified
outdated = inactive.days if inactive >= V5Config.NECROPOST_LIMIT else None
return render('/forum/topic.html', t=t, form=form, comments=comments, last=last_updated_comment)
return render('/forum/topic.html', t=t, form=form, comments=comments,
outdated=outdated)

View File

@ -19,10 +19,9 @@
{{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }}
{% if last %}
{% if outdated %}
<div class="bg-warn">
Ce topic est sans activité depuis plus de X jours, êtes-vous sûr de vouloir y poster ?
{{ last }}
Ce topic est sans activité depuis plus de {{ outdated }} jours, êtes-vous sûr de vouloir y poster ?
</div>
{% endif %}

View File

@ -1,4 +1,5 @@
import os
from datetime import timedelta
try:
from local_config import LocalConfig
@ -52,8 +53,8 @@ class DefaultConfig(object):
# GLaDOS configuration
GLADOS_HOST = "127.0.0.1"
GLADOS_PORT = 5555
# Time in days before trigerring the nec
NECROPOST_LIMIT = 31
# Time before trigerring the necropost alert
NECROPOST_LIMIT = timedelta(days=31)
class V5Config(LocalConfig, DefaultConfig):