pagination header
This commit is contained in:
@@ -11,3 +11,6 @@ def get_all():
|
||||
|
||||
def search(s):
|
||||
return Article.query.filter(Article.title.like("%"+s+"%")).order_by(Article.published_date.desc()).limit(20).all()
|
||||
|
||||
def get_all_page(lim, off):
|
||||
return Article.query.order_by(Article.published_date.desc()).limit(lim).offset(off).all()
|
||||
|
||||
@@ -124,19 +124,6 @@ class Article(Base):
|
||||
|
||||
#json.JSONEncoder.default = lambda self,obj: ((ArticleSchema().dump(obj)[0]) if isinstance(obj, Article) else None)
|
||||
|
||||
class ArticleCompSchema(Schema):
|
||||
id=fields.Integer()
|
||||
# text=fields.String()
|
||||
title=fields.String()
|
||||
author=fields.String()
|
||||
sourcetype =fields.String()
|
||||
image =fields.String()
|
||||
url =fields.String()
|
||||
published_date=fields.DateTime()
|
||||
date=fields.DateTime()
|
||||
first_fetched=fields.DateTime()
|
||||
section_id=fields.Integer()
|
||||
|
||||
class ArticleSchema(Schema):
|
||||
id=fields.Integer()
|
||||
text=fields.String()
|
||||
|
||||
@@ -20,8 +20,12 @@ import controller
|
||||
@article_pages.route("")
|
||||
@article_pages.route(".json")
|
||||
def index():
|
||||
articles=controller.get_all()
|
||||
return jsonify(articles=articles)
|
||||
articles=controller.get_all(20,0)
|
||||
resp = jsonify(articles=articles)
|
||||
resp.headers['Pagination-Limit']=20
|
||||
resp.headers['Pagination-Offset']=10
|
||||
resp.headers['Pagination-TotalCount']=100
|
||||
return resp
|
||||
|
||||
@article_pages.route("/<int:id>",methods=['PUT'])
|
||||
@article_pages.route("/<int:id>.json",methods=['PUT'])
|
||||
|
||||
Reference in New Issue
Block a user