def paginator(objects, request, default_page=1, default_size=50): """ Get from request page and page_size and return paginated objects :param objects: all queryset :param request: view request object :param default_page: start page if there is no page in GET :param default_size: page size if there is no page in GET :return: paginated objects """ page_size = request.GET.get('page_size', request.GET.get('length', default_size)) if 'start' in request.GET: page = int_from_request(request.GET, 'start', default_page) page = page / int(page_size) + 1 else: page = int_from_request(request.GET, 'page', default_page) if page_size == '-1': return objects else: paginator = Paginator(objects, page_size) return paginator.page(page).object_list
def paginator(objects, request, default_page=1, default_size=50): """ DEPRECATED TODO: change to standard drf pagination class Get from request page and page_size and return paginated objects :param objects: all queryset :param request: view request object :param default_page: start page if there is no page in GET :param default_size: page size if there is no page in GET :return: paginated objects """ page_size = request.GET.get('page_size', request.GET.get('length', default_size)) if settings.TASK_API_PAGE_SIZE_MAX and ( int(page_size) > settings.TASK_API_PAGE_SIZE_MAX or page_size == '-1'): page_size = settings.TASK_API_PAGE_SIZE_MAX if 'start' in request.GET: page = int_from_request(request.GET, 'start', default_page) if page and int(page) > int(page_size) > 0: page = int(page / int(page_size)) + 1 else: page += 1 else: page = int_from_request(request.GET, 'page', default_page) if page_size == '-1': return objects try: return Paginator(objects, page_size).page(page).object_list except ZeroDivisionError: return [] except EmptyPage: return []