rest_framework_dso.pagination module

The paginator classes implement the DSO specific response format for pagination.

This is essentially HAL-JSON style pagination as described in: https://tools.ietf.org/html/draft-kelly-json-hal-08

class rest_framework_dso.pagination.DSOHTTPHeaderPageNumberPagination

Bases: PageNumberPagination

Paginator that only adds the DSO HTTP Header fields:

  • X-Pagination-Page: page number

  • X-Pagination-Limit: page size

  • X-Pagination-Count: number of pages (optional)

  • X-Total-Count: total number of results (optional)

This can be used for for non-JSON exports (e.g. CSV files).

django_paginator_class

alias of DSOPaginator

get_page_size(request)

Allow the page_size parameter was fallback.

get_paginated_response(data) Response

Adds the DSO HTTP headers only. It wraps the data in the Response object.

get_schema_operation_parameters(view)

Return the supported query parameters for this Pagination style. Used by the SchemaGenerator to supply these to the openapi schema.

page_query_param = 'page'

The page number query parameter.

page_size_query_param = '_pageSize'

The page size query parameter.

paginate_queryset(queryset, request, view=None)

Optimized base class logic, to return a queryset instead of list.

class rest_framework_dso.pagination.DSOPageNumberPagination(results_field=None)

Bases: DelegatedPageNumberPagination

Pagination style as the DSO requires.

It wraps the response in a few standard objects:

{
    "_embedded": {
        "results_field": [
            ...,
            ...,
        ]
    },
    "_links": {
        "self": {"href": ...},
        "next": {"href": ...},
        "previous": {"href": ...},
    },
    "page": {
        "number": ...,
        "size": ...,
        "totalElements": ...,
        "totalPages": ...,
    }
}

The '_links' and 'page' attribute can be retrieved with the get_footer method,
after the result_field has been streamed so the number of items in the result_set is known.
__init__(results_field=None)

Allow to override the results_field on construction

Generate the links and page fields

Generate the links field

get_page() dict

Generate the page field

get_paginated_response(data)

Wrap the data in all pagination parts.

get_paginated_response_schema(schema: dict) dict

Tell what the OpenAPI schema looks like. This is directly used by the OpenAPI results for paginated views.

get_results(data)

Implement DRF hook for completeness, can be used by the browsable API.

results_field = None

The field name for the results envelope

class rest_framework_dso.pagination.DelegatedPageNumberPagination

Bases: DSOHTTPHeaderPageNumberPagination

Delegate the pagination rendering to the output renderer.

In the design of Django-Rest-Framework, the output renderer and pagination are separate object types. While such approach sort-of works for JSON-style responses, it’s problematic for other file formats such as CSV/GeoJSON.

Instead of letting the paginator render the pagination for various formats, this renderer class delegates that task to the current output renderer. For this, the output renderer class must implement a setup_pagination() function.

get_paginated_response(data)

Adds the DSO HTTP headers only. It wraps the data in the Response object.