from django.conf import settings


def retrieve_all_pages(api_endpoint, **kwargs):
    """
    Some MTP apis are paginated, this method loads all pages into a single results list
    :param api_endpoint: slumber callable, e.g. `[api_client].cashbook.transactions.locked.get`
    :param kwargs: additional arguments to pass into api callable
    """
    loaded_results = []

    offset = 0
    while True:
        response = api_endpoint(limit=settings.REQUEST_PAGE_SIZE, offset=offset,
                                **kwargs)
        count = response.get('count', 0)
        loaded_results += response.get('results', [])
        if len(loaded_results) >= count:
            break
        offset += settings.REQUEST_PAGE_SIZE

    return loaded_results

Add retrieve_all_pages util method from mtp-cashbook
Add retrieve_all_pages util method from mtp-cashbook

This method is duplicated in functionality in multiple
front end apps.
