<s> from __future__ import absolute_import , unicode_literals <EOL> from collections import OrderedDict <EOL> from django . conf import settings <EOL> from rest_framework . pagination import BasePagination <EOL> from rest_framework . response import Response <EOL> from . utils import BadRequestError <EOL> class WagtailPagination ( BasePagination ) : <EOL> def paginate_queryset ( self , queryset , request , view = None ) : <EOL> limit_max = getattr ( settings , '<STR_LIT>' , <NUM_LIT:20> ) <EOL> try : <EOL> offset = int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> assert offset >= <NUM_LIT:0> <EOL> except ( ValueError , AssertionError ) : <EOL> raise BadRequestError ( "<STR_LIT>" ) <EOL> try : <EOL> limit = int ( request . GET . get ( '<STR_LIT>' , min ( <NUM_LIT:20> , limit_max ) ) ) <EOL> if limit > limit_max : <EOL> raise BadRequestError ( "<STR_LIT>" % limit_max ) <EOL> assert limit >= <NUM_LIT:0> <EOL> except ( ValueError , AssertionError ) : <EOL> raise BadRequestError ( "<STR_LIT>" ) <EOL> start = offset <EOL> stop = offset + limit <EOL> self . view = view <EOL> self . total_count = queryset . count ( ) <EOL> return queryset [ start : stop ] <EOL> def get_paginated_response ( self , data ) : <EOL> data = OrderedDict ( [ <EOL> ( '<STR_LIT>' , OrderedDict ( [ <EOL> ( '<STR_LIT>' , self . total_count ) , <EOL> ] ) ) , <EOL> ( '<STR_LIT>' , data ) , <EOL> ] ) <EOL> return Response ( data ) </s>
