Debian Codegraph @

rest_framework_gis/pagination.py

raw
1 from collections import OrderedDict
2
3 from rest_framework import pagination
4 from rest_framework.response import Response
5
6
7 class GeoJsonPagination(pagination.PageNumberPagination):
8 """
9 A geoJSON implementation of a pagination serializer.
10 """
11
12 page_size_query_param = "page_size"
13
14 def get_paginated_response(self, data):
15 return Response(
16 OrderedDict(
17 [
18 ("type", "FeatureCollection"),
19 ("count", self.page.paginator.count),
20 ("next", self.get_next_link()),
21 ("previous", self.get_previous_link()),
22 ("features", data["features"]),
23 ]
24 )
25 )
26
27 def get_paginated_response_schema(self, view):
28 schema = super().get_paginated_response_schema(view)
29 schema["properties"]["features"] = schema["properties"].pop("results")
30 schema["properties"] = {
31 "type": {"type": "string", "enum": ["FeatureCollection"]},
32 **schema["properties"],
33 }
34 return schema