diff --git a/app/routes/forum/topic.py b/app/routes/forum/topic.py index 6a3f2e3..c5dab42 100644 --- a/app/routes/forum/topic.py +++ b/app/routes/forum/topic.py @@ -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//', 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) diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 8353ae5..657f6a7 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -19,10 +19,9 @@ {{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }} - {% if last %} + {% if outdated %}
- 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 ?
{% endif %} diff --git a/config.py b/config.py index 7110ba9..b666f25 100644 --- a/config.py +++ b/config.py @@ -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):