count fix 2

This commit is contained in:
Andreas Stephanides
2017-01-26 16:28:39 +01:00
parent 619c0ea121
commit dc835e9788
2 changed files with 6 additions and 1 deletions

View File

@@ -45,3 +45,6 @@ def get_section_page(section_id, lim, off):
def section_count(section_id): def section_count(section_id):
return Article.query.filter(Article.section_id==section_id).count() return Article.query.filter(Article.section_id==section_id).count()
def count():
return Article.query.count()

View File

@@ -24,12 +24,14 @@ def index():
pp,o=controller.pagination_params(v) # extract per_page and offset from params pp,o=controller.pagination_params(v) # extract per_page and offset from params
if v.has_key("section_id"): if v.has_key("section_id"):
articles=controller.get_section_page(int(v["section_id"]),pp,o) articles=controller.get_section_page(int(v["section_id"]),pp,o)
c=controller.section_count(int(v["section_id"]))
else: else:
articles=controller.get_all_page(pp,o) articles=controller.get_all_page(pp,o)
c=controller.count()
resp = jsonify(articles=articles) resp = jsonify(articles=articles)
resp.headers['Pagination-Limit']=pp resp.headers['Pagination-Limit']=pp
resp.headers['Pagination-Offset']=o resp.headers['Pagination-Offset']=o
resp.headers['Pagination-TotalCount']=controller.count() resp.headers['Pagination-TotalCount']=c
return resp return resp
@article_pages.route("/<int:id>",methods=['PUT']) @article_pages.route("/<int:id>",methods=['PUT'])