From dc835e97882aadab453e32206541e7e67c23984d Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 26 Jan 2017 16:28:39 +0100 Subject: [PATCH] count fix 2 --- articles/controller.py | 3 +++ articles/views.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/articles/controller.py b/articles/controller.py index c91f294..13464f1 100644 --- a/articles/controller.py +++ b/articles/controller.py @@ -45,3 +45,6 @@ def get_section_page(section_id, lim, off): def section_count(section_id): return Article.query.filter(Article.section_id==section_id).count() + +def count(): + return Article.query.count() diff --git a/articles/views.py b/articles/views.py index 829d575..c5bfb1d 100644 --- a/articles/views.py +++ b/articles/views.py @@ -24,12 +24,14 @@ def index(): pp,o=controller.pagination_params(v) # extract per_page and offset from params if v.has_key("section_id"): articles=controller.get_section_page(int(v["section_id"]),pp,o) + c=controller.section_count(int(v["section_id"])) else: articles=controller.get_all_page(pp,o) + c=controller.count() resp = jsonify(articles=articles) resp.headers['Pagination-Limit']=pp resp.headers['Pagination-Offset']=o - resp.headers['Pagination-TotalCount']=controller.count() + resp.headers['Pagination-TotalCount']=c return resp @article_pages.route("/",methods=['PUT'])