@@ -0,0 +1,1316 @@
+%22%22%22%0Acustom pagination support%0A%22%22%22%0Afrom rest_framework.pagination import PageNumberPagination%0A%0A# NOTE: this value is set here for v1 api support%0ADEFAULT_PAGINATION_SIZE = 20%0A%0A%0Adef _is_positive(integer_string):%0A    %22%22%22%0A    Check if a string is a strictly positive integer.%0A    %22%22%22%0A    return int(integer_string) %3E 0%0A%0A%0Adef _get_count(queryset):%0A    %22%22%22%0A    Determine an object count, supporting either querysets or regular lists.%0A    %22%22%22%0A    try:%0A        return queryset.count()%0A    except (AttributeError, TypeError):%0A        return len(queryset)%0A%0A%0Aclass OptionalPagination(PageNumberPagination):%0A    %22%22%22%0A    Defaults to no pagination but supports pagination%0A    %22%22%22%0A    page_size_query_param = 'page_size'%0A    max_page_size = None%0A%0A    def paginate_queryset(self, queryset, request, view=None):%0A        if self.has_page(request):%0A            self.page_size = DEFAULT_PAGINATION_SIZE%0A        else:%0A            self.page_size = _get_count(queryset)%0A%0A        return super(OptionalPagination, self).paginate_queryset(%0A            queryset, request, view=view)%0A%0A    def has_page(self, request):%0A        %22%22%22%0A        Checks whether a page has been specified%0A        %22%22%22%0A        try:%0A            return _is_positive(request.query_params%5Bself.page_query_param%5D)%0A        except (KeyError, ValueError):%0A            return False%0A

add pagination class for optional pagination