From 748a45f2e7b8de3928c0462304299c9751f729ed Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Fri, 26 May 2017 06:47:14 +0200 Subject: added pagination for bookmarks --- src/web/templates/bookmarks.html | 3 +++ src/web/views/bookmark.py | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/web/templates/bookmarks.html b/src/web/templates/bookmarks.html index 96f38d26..39528322 100644 --- a/src/web/templates/bookmarks.html +++ b/src/web/templates/bookmarks.html @@ -1,6 +1,8 @@ {% extends "layout.html" %} {% block content %}
+ {{ pagination.info }} + {{ pagination.links }} + {{ pagination.links }}
{% endblock %} diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py index f619dc25..2f6df6bd 100644 --- a/src/web/views/bookmark.py +++ b/src/web/views/bookmark.py @@ -33,6 +33,7 @@ from flask import Blueprint, render_template, flash, \ redirect, request, url_for from flask_babel import gettext from flask_login import login_required, current_user +from flask_paginate import Pagination, get_page_args from sqlalchemy import desc import conf @@ -47,16 +48,25 @@ bookmarks_bp = Blueprint('bookmarks', __name__, url_prefix='/bookmarks') bookmark_bp = Blueprint('bookmark', __name__, url_prefix='/bookmark') -@bookmarks_bp.route('/', methods=['GET']) +@bookmarks_bp.route('/', defaults={'per_page': '50'}, methods=['GET']) @login_required -def list(): +def list(per_page): "Lists the bookmarks." head_titles = ["Bookmarks"] + + page, per_page, offset = get_page_args() bookmark_contr = BookmarkController(current_user.id) + bookmarks = bookmark_contr.read().order_by(desc('time')) + + pagination = Pagination(page=page, total=bookmarks.count(), + css_framework='bootstrap3', + search=False, record_name='bookmarks', + per_page=per_page) + return render_template('bookmarks.html', - head_titles=head_titles, - bookmarks=BookmarkController(current_user.id) \ - .read().order_by(desc('time'))) + head_titles=head_titles, + bookmarks=bookmarks.offset(offset).limit(per_page), + pagination=pagination) @bookmark_bp.route('/create', methods=['GET']) -- cgit