article pagination

This commit is contained in:
Andreas Stephanides
2017-01-22 10:21:08 +01:00
parent e5bccfe7da
commit 5006c9fbe3

View File

@@ -21,6 +21,7 @@ import controller
@article_pages.route(".json") @article_pages.route(".json")
def index(): def index():
v=request.values v=request.values
try:
if v.has_key("per_page"): if v.has_key("per_page"):
pp=int(v["per_page"]) pp=int(v["per_page"])
else: else:
@@ -29,6 +30,13 @@ def index():
o=(int(v["page"])-1) *pp o=(int(v["page"])-1) *pp
else: else:
o=0 o=0
except ValueError:
pp=20
o=0
if not (isinstance(pp,int) and pp>0 and pp<10000):
pp=20
if not (isinstance(o,int) and o>=0 and o<100000):
o=0
articles=controller.get_all_page(pp,o) articles=controller.get_all_page(pp,o)
resp = jsonify(articles=articles) resp = jsonify(articles=articles)
resp.headers['Pagination-Limit']=pp resp.headers['Pagination-Limit']=pp