From e5bccfe7da3be84a5f142498251affdd3c49f203 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 22 Jan 2017 10:06:13 +0100 Subject: [PATCH] correct pagination headers --- articles/controller.py | 3 +++ articles/views.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/articles/controller.py b/articles/controller.py index 5f59f1d..3ec5bcc 100644 --- a/articles/controller.py +++ b/articles/controller.py @@ -14,3 +14,6 @@ def search(s): def get_all_page(lim, off): return Article.query.order_by(Article.published_date.desc()).limit(lim).offset(off).all() + +def count(): + return Article.query.count() diff --git a/articles/views.py b/articles/views.py index 7348158..6c0f1d0 100644 --- a/articles/views.py +++ b/articles/views.py @@ -31,9 +31,9 @@ def index(): o=0 articles=controller.get_all_page(pp,o) resp = jsonify(articles=articles) - resp.headers['Pagination-Limit']=20 - resp.headers['Pagination-Offset']=10 - resp.headers['Pagination-TotalCount']=100 + resp.headers['Pagination-Limit']=pp + resp.headers['Pagination-Offset']=o + resp.headers['Pagination-TotalCount']=controller.count() return resp @article_pages.route("/",methods=['PUT'])