Ajout du load dynmaique des messages (#39)

This commit is contained in:
Darks 2019-12-07 16:06:00 +01:00
parent 94badf4bad
commit a2e408daf9
Signed by: Darks
GPG Key ID: F61F10FA138E797C
4 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from app import db
from app.models.post import Post
from sqlalchemy.orm import backref
class Comment(Post):
__tablename__ = 'comment'
@ -14,7 +15,8 @@ class Comment(Post):
# Parent thread
thread_id = db.Column(db.Integer, db.ForeignKey('thread.id'),
nullable=False)
thread = db.relationship('Thread', backref='comments',
thread = db.relationship('Thread',
backref=backref('comments', lazy='dynamic'),
foreign_keys=thread_id)
def __init__(self, author, text, thread):

View File

@ -38,4 +38,12 @@ def forum_topic(f, t):
db.session.merge(t)
db.session.commit()
return render('/forum/topic.html', t=t, form=form)
if request.args.get('page') == "last":
page = t.thread.comments.count() // V5Config.COMMENTS_PER_PAGE + 1
else:
page = request.args.get('page', 1, type=int)
comments = t.thread.comments.paginate(page,
V5Config.COMMENTS_PER_PAGE, True)
return render('/forum/topic.html', t=t, form=form, comments=comments)

View File

@ -15,7 +15,7 @@
</tr></table>
<table class="thread">
{% for i, c in enumerate(t.thread.comments) %}
{% for c in comments.items %}
<tr>
{% if c != t.thread.top_comment %}
<td class="member">{{ widget_member.profile(c.author ) }}</td>
@ -27,7 +27,7 @@
{% endif %}
<hr>
<p>{{ c.text }}</p>
{% elif i != 0 %}
{% elif loop.index0 != 0 %}
<div>Ce message est le top comment</div>
{% endif %}
</td>

View File

@ -25,6 +25,8 @@ class V5Config(LocalConfig):
PASSWORD_MINLEN = 10
# Maximum thread name length
THREAD_NAME_MAXLEN = 32
# Amount of comments per thread page
COMMENTS_PER_PAGE = 20
# Remember-me cookie duration time
REMEMBER_COOKIE_DURATION = datetime.timedelta(days=7)
# XP points for content posting (and deletion)