diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-05-26 06:47:14 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-05-26 06:47:14 +0200 |
commit | 748a45f2e7b8de3928c0462304299c9751f729ed (patch) | |
tree | 665974a37ffc0cd12609861af59debc06da5bc3f | |
parent | Bumped version number for Heroku. (diff) | |
download | newspipe-748a45f2e7b8de3928c0462304299c9751f729ed.tar.gz newspipe-748a45f2e7b8de3928c0462304299c9751f729ed.tar.bz2 newspipe-748a45f2e7b8de3928c0462304299c9751f729ed.zip |
added pagination for bookmarks
-rw-r--r-- | requirements.txt | 1 | ||||
-rw-r--r-- | src/web/templates/bookmarks.html | 3 | ||||
-rw-r--r-- | src/web/views/bookmark.py | 20 |
3 files changed, 19 insertions, 5 deletions
diff --git a/requirements.txt b/requirements.txt index 2f627cd4..751e5949 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ Flask-Principal==0.4.0 Flask-WTF==0.14.2 Flask-RESTful==0.3.5 Flask-Restless==0.17.0 +Flask-paginate==0.4.5 Flask-Babel==0.11.1 Flask-SSLify==0.1.5 Flask-Migrate==2.0.3 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 %} <div class="container"> + {{ pagination.info }} + {{ pagination.links }} <ul class="list-group"> {% for bookmark in bookmarks %} <li class="list-group-item"> @@ -19,5 +21,6 @@ </li> {% endfor %} </ul> + {{ pagination.links }} </div><!-- /.container --> {% 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']) |