def get(self): ''' Support pagination style: 'page' json parameter. Returns a list of customers and pagination data. ''' form = CustomerListForm.from_json(request.get_json()) if not form.validate(): return jsonify(errors=form.errors) page = form.page.data total = CustomerService.get_count_customers() total_pages = ceil(total / CustomerService.RESULTS_PER_PAGE) start = page * CustomerService.RESULTS_PER_PAGE stop = start + CustomerService.RESULTS_PER_PAGE raw_customers = CustomerService.get_customers( start=start, stop=stop ) return jsonify( current_page=page, total_pages=int(total_pages), customers=[customer.json for customer in raw_customers] )
def get(self): ''' Support pagination style: 'page' json parameter. Returns a list of customers and pagination data. ''' form = CustomerListForm.from_json(request.get_json()) if not form.validate(): return jsonify(errors=form.errors) page = form.page.data total = CustomerService.get_count_customers() total_pages = ceil(total / CustomerService.RESULTS_PER_PAGE) start = page * CustomerService.RESULTS_PER_PAGE stop = start + CustomerService.RESULTS_PER_PAGE raw_customers = CustomerService.get_customers(start=start, stop=stop) return jsonify(current_page=page, total_pages=int(total_pages), customers=[customer.json for customer in raw_customers])