Ajout de la pagination pour les topics de forum
This commit is contained in:
parent
bdf23d8a67
commit
b4341ed0f8
|
@ -1,9 +1,11 @@
|
|||
from app import app
|
||||
from flask import url_for
|
||||
|
||||
@app.context_processor
|
||||
def utilities_processor():
|
||||
""" Add some utilities to render context """
|
||||
return dict(
|
||||
# len=len,
|
||||
# enumerate=enumerate
|
||||
len=len,
|
||||
# enumerate=enumerate,
|
||||
_url_for = lambda route, args, **other: url_for(route, **args, **other),
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{% extends "base/base.html" %}
|
||||
{% import "widgets/editor.html" as widget_editor %}
|
||||
{% import "widgets/member.html" as widget_member %}
|
||||
{% import "widgets/pagination.html" as widget_pagination with context %}
|
||||
|
||||
{% block title %}
|
||||
<a href='/forum'>Forum de Planète Casio</a> » <a href="{{ url_for('forum_page', f=t.forum) }}">{{ t.forum.name }}</a> » <h1>{{ t.title }}</h1>
|
||||
|
@ -14,6 +15,8 @@
|
|||
<td>{{ t.thread.top_comment.text }}</td>
|
||||
</tr></table>
|
||||
|
||||
{{ widget_pagination.paginate(comments, 'forum_topic', {'f': t.forum, 't':t}) }}
|
||||
|
||||
<table class="thread">
|
||||
{% for c in comments.items %}
|
||||
<tr>
|
||||
|
@ -35,6 +38,8 @@
|
|||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{{ widget_pagination.paginate(comments, 'forum_topic', {'f': t.forum, 't':t}) }}
|
||||
|
||||
<div class=form>
|
||||
<h3>Commenter le sujet</h3>
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{% macro paginate(objects, route, route_args) %}
|
||||
<div class="pagination">
|
||||
{% if objects.has_prev %}
|
||||
<a href="{{ _url_for(route, route_args, page=objects.prev_num) }}">Page précédente</a> |
|
||||
{% endif %}
|
||||
|
||||
{% for page in objects.iter_pages(1, 5, 6, 1) %}
|
||||
{% if page %}
|
||||
{% if page != objects.page %}
|
||||
<a href="{{ _url_for(route, route_args, page=page) }}">{{ page }}</a>
|
||||
{% else %}
|
||||
<strong>{{ page }}</strong>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class=ellipsis>…</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if objects.has_next %}
|
||||
| <a href="{{ _url_for(route, route_args, page=objects.next_num) }}">Page suivante</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
Loading…
Reference in New Issue