diff --git a/articles/controller.py b/articles/controller.py index f5109c7..5f59f1d 100644 --- a/articles/controller.py +++ b/articles/controller.py @@ -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() diff --git a/articles/model.py b/articles/model.py index 710f9c2..26af34f 100644 --- a/articles/model.py +++ b/articles/model.py @@ -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() diff --git a/articles/views.py b/articles/views.py index b31772f..923549f 100644 --- a/articles/views.py +++ b/articles/views.py @@ -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("/",methods=['PUT']) @article_pages.route("/.json",methods=['PUT'])