Browse Source

Cursor Pagination matches OSS Sentry more, allows gitlab issue tracking
to support previous and next

David Burke 4 years ago
parent
commit
0fac64930f
1 changed files with 13 additions and 3 deletions
  1. 13 3
      glitchtip/pagination.py

+ 13 - 3
glitchtip/pagination.py

@@ -1,3 +1,5 @@
+import urllib.parse as urlparse
+from urllib.parse import parse_qs
 from rest_framework.pagination import CursorPagination
 from rest_framework.response import Response
 
@@ -25,13 +27,21 @@ class LinkHeaderPagination(CursorPagination):
 
         links = []
         for url, label in (
-            (previous_url, "prev"),
+            (previous_url, "previous"),
             (next_url, "next"),
         ):
             if url is not None:
-                links.append('<{}>; rel="{}"; results="true"'.format(url, label))
+                parsed = urlparse.urlparse(url)
+                cursor = parse_qs(parsed.query).get(self.cursor_query_param, [""])[0]
+                links.append(
+                    '<{}>; rel="{}"; results="true"; cursor="{}"'.format(
+                        url, label, cursor
+                    )
+                )
             else:
-                links.append('<>; rel="{}"; results="false"'.format(label))
+                links.append(
+                    '<{}>; rel="{}"; results="false"'.format(self.base_url, label)
+                )
 
         headers = {"Link": ", ".join(links)} if links else {}