2
2
Pagination fields
3
3
"""
4
4
# pylint: disable=no-init, too-few-public-methods, no-self-use
5
-
5
+ from collections import OrderedDict
6
6
7
7
from rest_framework import serializers
8
8
from rest_framework import pagination
@@ -108,6 +108,7 @@ class PageNumberPagination(BasePagination):
108
108
"""
109
109
An Ember (soon to be json-api) compatible pagination format
110
110
"""
111
+
111
112
def build_link (self , index ):
112
113
if not index :
113
114
return None
@@ -126,16 +127,18 @@ def get_paginated_response(self, data):
126
127
return Response ({
127
128
'results' : data ,
128
129
'meta' : {
129
- 'pagination' : {
130
- 'page' : self .page .number ,
131
- 'count' : self .page .paginator .count ,
132
- 'total' : self .page .paginator .num_pages ,
133
- }
130
+ 'pagination' : OrderedDict ([
131
+ ('page' , self .page .number ),
132
+ ('count' , self .page .paginator .count ),
133
+ ('total' , self .page .paginator .num_pages ),
134
+ ('start_index' , self .page .start_index () - 1 ),
135
+ ('end_index' , self .page .end_index () - 1 ),
136
+ ])
134
137
},
135
- 'links' : {
136
- 'first' : self .build_link (self . page . start_index ( )),
137
- 'last' : self .build_link (self .page .end_index ( )),
138
- 'next' : self .build_link (next ),
139
- 'prev' : self .build_link (previous ),
140
- }
138
+ 'links' : OrderedDict ([
139
+ ( 'first' , self .build_link (1 )),
140
+ ( 'last' , self .build_link (self .page .paginator . num_pages )),
141
+ ( 'next' , self .build_link (next ) ),
142
+ ( 'prev' , self .build_link (previous ))
143
+ ])
141
144
})
0 commit comments