def get_objects(self, page=1): if not self.d.get('pagination'): # api form, we retrieve all packages try: packages = qry.get_all_packages(session).all() packages = [p.to_dict() for p in packages] return dict(packages=packages) except Exception as e: raise Http500Error(e) else: # we paginate # WARNING: not serializable (TODO: serialize Pagination obj) try: offset = int(app.config.get("LIST_OFFSET") or 60) # we calculate the range of results start = (page - 1) * offset end = start + offset count_packages = qry.count_packages(session) packages = (qry.get_all_packages(session) .slice(start, end) ) pagination = Pagination(page, offset, count_packages) return dict(packages=packages, page=page, pagination=pagination) except Exception as e: raise Http500Error(e)