Add basic API endpoint for upgrades, partial pagination support

latter is still broken, but this much is a starting point i think
This commit is contained in:
Lance Edgar 2018-11-01 00:34:28 -05:00
parent 0c41395cfc
commit b8fdce378f
3 changed files with 63 additions and 0 deletions

View file

@ -26,6 +26,8 @@ Tailbone Web API - Master View
from __future__ import unicode_literals, absolute_import
from paginate_sqlalchemy import SqlalchemyOrmPage
from tailbone.api import APIView, api
from tailbone.db import Session
@ -83,6 +85,15 @@ class APIMasterView(APIView):
sortkey = getattr(self.model_class, sortkey)
objects = objects.order_by(getattr(sortkey, sortdir)())
# NOTE: we only page results if sorting is in effect, otherwise
# record sequence is "non-determinant" (is that the word?)
page = self.request.params.get('page')
per_page = self.request.params.get('per_page')
if page.isdigit() and per_page.isdigit():
page = int(page)
per_page = int(per_page)
objects = SqlalchemyOrmPage(objects, items_per_page=per_page, page=page)
data = [self.normalize(obj) for obj in objects]
return data