def get_paginated_list(klass, url=None, args={}, **kwargs):
 if ('event_id' in kwargs):
  get_object_or_404(EventModel, kwargs['event_id'])
 if (url is None):
  url = request.base_url
 start = args['start']
 limit = args['limit']
 results = get_object_list(klass, **kwargs)
 count = len(results)
 if (count < start):
  raise NotFoundError(message="Start position '{}' out of bound".format(start))
 obj = {}
 obj['start'] = start
 obj['limit'] = limit
 obj['count'] = count
 args_copy = args.copy()
 if (start == 1):
  obj['previous'] = ''
 else:
  args_copy['start'] = max(1, (start - limit))
  args_copy['limit'] = (start - 1)
  obj['previous'] = (url + _make_url_query(args_copy))
 args_copy = args.copy()
 if ((start + limit) > count):
  obj['next'] = ''
 else:
  args_copy['start'] = (start + limit)
  obj['next'] = (url + _make_url_query(args_copy))
 obj['results'] = results[(start - 1):((start - 1) + limit)]
 return obj

def get_paginated_list ( klass , url = None , args = { } , ** kwargs ) : if ( 'event_id' in kwargs ) : get_object_or_404 ( EventModel , kwargs [ 'event_id' ] ) if ( url is None ) : url = request . base_url start = args [ 'start' ] limit = args [ 'limit' ] results = get_object_list ( klass , ** kwargs ) count = len ( results ) if ( count < start ) : raise NotFoundError ( message = "Start position '{}' out of bound" . format ( start ) ) obj = { } obj [ 'start' ] = start obj [ 'limit' ] = limit obj [ 'count' ] = count args_copy = args . copy ( ) if ( start == 1 ) : obj [ 'previous' ] = '' else : args_copy [ 'start' ] = max ( 1 , ( start - limit ) ) args_copy [ 'limit' ] = ( start - 1 ) obj [ 'previous' ] = ( url + _make_url_query ( args_copy ) ) args_copy = args . copy ( ) if ( ( start + limit ) > count ) : obj [ 'next' ] = '' else : args_copy [ 'start' ] = ( start + limit ) obj [ 'next' ] = ( url + _make_url_query ( args_copy ) ) obj [ 'results' ] = results [ ( start - 1 ) : ( ( start - 1 ) + limit ) ] return obj
returns a paginated response object klass - model class to query from url - url of the request args - args passed to the request as query parameters kwargs - filters for query on the klass model .