12
12
from django .core .paginator import InvalidPage
13
13
from django .template import loader
14
14
from django .utils import six
15
+ from django .utils .encoding import force_text
15
16
from django .utils .six .moves .urllib import parse as urlparse
16
17
from django .utils .translation import ugettext_lazy as _
17
18
@@ -178,10 +179,12 @@ class PageNumberPagination(BasePagination):
178
179
179
180
# Client can control the page using this query parameter.
180
181
page_query_param = 'page'
182
+ page_query_description = _ ('A page number within the paginated result set.' )
181
183
182
184
# Client can control the page size using this query parameter.
183
185
# Default is 'None'. Set to eg 'page_size' to enable usage.
184
186
page_size_query_param = None
187
+ page_size_query_description = _ ('Number of results to return per page.' )
185
188
186
189
# Set to an integer to limit the maximum page size the client may request.
187
190
# Only relevant if 'page_size_query_param' has also been set.
@@ -287,11 +290,21 @@ def to_html(self):
287
290
def get_schema_fields (self , view ):
288
291
assert coreapi is not None , 'coreapi must be installed to use `get_schema_fields()`'
289
292
fields = [
290
- coreapi .Field (name = self .page_query_param , required = False , location = 'query' )
293
+ coreapi .Field (
294
+ name = self .page_query_param ,
295
+ required = False ,
296
+ location = 'query' ,
297
+ description = force_text (self .page_query_description )
298
+ )
291
299
]
292
300
if self .page_size_query_param is not None :
293
301
fields .append (
294
- coreapi .Field (name = self .page_size_query_param , required = False , location = 'query' )
302
+ coreapi .Field (
303
+ name = self .page_size_query_param ,
304
+ required = False ,
305
+ location = 'query' ,
306
+ description = force_text (self .page_size_query_description )
307
+ )
295
308
)
296
309
return fields
297
310
@@ -305,7 +318,9 @@ class LimitOffsetPagination(BasePagination):
305
318
"""
306
319
default_limit = api_settings .PAGE_SIZE
307
320
limit_query_param = 'limit'
321
+ limit_query_description = _ ('Number of results to return per page.' )
308
322
offset_query_param = 'offset'
323
+ offset_query_description = _ ('The initial index from which to return the results.' )
309
324
max_limit = None
310
325
template = 'rest_framework/pagination/numbers.html'
311
326
@@ -425,8 +440,18 @@ def to_html(self):
425
440
def get_schema_fields (self , view ):
426
441
assert coreapi is not None , 'coreapi must be installed to use `get_schema_fields()`'
427
442
return [
428
- coreapi .Field (name = self .limit_query_param , required = False , location = 'query' ),
429
- coreapi .Field (name = self .offset_query_param , required = False , location = 'query' )
443
+ coreapi .Field (
444
+ name = self .limit_query_param ,
445
+ required = False ,
446
+ location = 'query' ,
447
+ description = force_text (self .limit_query_description )
448
+ ),
449
+ coreapi .Field (
450
+ name = self .offset_query_param ,
451
+ required = False ,
452
+ location = 'query' ,
453
+ description = force_text (self .offset_query_description )
454
+ )
430
455
]
431
456
432
457
@@ -437,6 +462,7 @@ class CursorPagination(BasePagination):
437
462
http://cramer.io/2011/03/08/building-cursors-for-the-disqus-api
438
463
"""
439
464
cursor_query_param = 'cursor'
465
+ cursor_query_description = _ ('The pagination cursor value.' )
440
466
page_size = api_settings .PAGE_SIZE
441
467
invalid_cursor_message = _ ('Invalid cursor' )
442
468
ordering = '-created'
@@ -739,5 +765,10 @@ def to_html(self):
739
765
def get_schema_fields (self , view ):
740
766
assert coreapi is not None , 'coreapi must be installed to use `get_schema_fields()`'
741
767
return [
742
- coreapi .Field (name = self .cursor_query_param , required = False , location = 'query' )
768
+ coreapi .Field (
769
+ name = self .cursor_query_param ,
770
+ required = False ,
771
+ location = 'query' ,
772
+ description = force_text (self .cursor_query_description )
773
+ )
743
774
]
0 commit comments