From c0a091a8c7ec2ff5232d6ed16d2d0736fc51fb49 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Thu, 26 Jan 2017 16:16:53 +0100 Subject: [PATCH] count articles per section --- articles/controller.py | 8 ++++++-- sections/views.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/articles/controller.py b/articles/controller.py index 1eeb213..c503718 100644 --- a/articles/controller.py +++ b/articles/controller.py @@ -39,5 +39,9 @@ def get_all_page(lim, off): def get_section_page(section_id, lim, off): return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all() -def count(): - return Article.query.count() + +def get_section_page(section_id, lim, off): + return Article.query.filter(Article.section_id==section_id).order_by(Article.published_date.desc()).limit(lim).offset(off).all() + +def section_count(section_id): + return Article.filter(Article.section_id==section_id).query.count() diff --git a/sections/views.py b/sections/views.py index e3a753d..72c6f38 100644 --- a/sections/views.py +++ b/sections/views.py @@ -48,7 +48,7 @@ def get_articles(id): resp = jsonify(articles=articles) resp.headers['Pagination-Limit']=pp resp.headers['Pagination-Offset']=o - resp.headers['Pagination-TotalCount']=controller.count() + resp.headers['Pagination-TotalCount']=article_controller.section_count(id) return resp