update: apply pagination to actor and contribution models
Updates these models to use LDPPagination
, example usage http://localhost:8000/actors/?limit=1&offset=1
LDPPagination ultimately uses Rest Framework's LimitOffsetPagination, but places next
and prev
as Link headers (complete code below)
class LDPPagination(LimitOffsetPagination):
def get_paginated_response(self, data):
next_url = self.get_next_link()
previous_url = self.get_previous_link()
links = []
for url, label in ((previous_url, 'prev'), (next_url, 'next')):
if url is not None:
links.append('<{}>; rel="{}"'.format(url, label))
headers = {'Link': ', '.join(links)} if links else {}
return Response(data, headers=headers)
For the front-end, this means that the next and previous pages can be found in the headers, and the response body is unchanged
Note also that if no limit
or offset
are included in the request parameters then it will not paginate the response