This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/endpoints/v2/v2util.py
2015-09-29 16:02:19 -04:00

19 lines
544 B
Python

from flask import request
from app import get_app_url
_MAX_RESULTS_PER_PAGE = 100
def add_pagination(query, url):
""" Adds optional pagination to the given query by looking for the Docker V2 pagination request
args. """
limit = request.args.get('n', None)
page = request.args.get('page', 1)
if limit is None:
return None, query
limit = max(limit, _MAX_RESULTS_PER_PAGE)
url = get_app_url() + url
query = query.paginate(page, limit)
link = url + '?n=%s&last=%s; rel="next"' % (limit, page + 1)
return link, query