mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
dev: add total pages key
This commit is contained in:
parent
8ea0528c7d
commit
26ec7323e5
@ -145,7 +145,7 @@ class OffsetPaginator:
|
|||||||
results=results,
|
results=results,
|
||||||
next=next_cursor,
|
next=next_cursor,
|
||||||
prev=prev_cursor,
|
prev=prev_cursor,
|
||||||
hits=None,
|
hits=count,
|
||||||
max_hits=max_hits,
|
max_hits=max_hits,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -197,9 +197,6 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
|||||||
if offset < 0:
|
if offset < 0:
|
||||||
raise BadPaginationError("Pagination offset cannot be negative")
|
raise BadPaginationError("Pagination offset cannot be negative")
|
||||||
|
|
||||||
# Get the queryset
|
|
||||||
queryset = self.queryset
|
|
||||||
|
|
||||||
# Compute the results
|
# Compute the results
|
||||||
results = {}
|
results = {}
|
||||||
queryset = queryset.annotate(
|
queryset = queryset.annotate(
|
||||||
@ -211,7 +208,7 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Filter the results
|
# Filter the results
|
||||||
results = queryset.filter(row_number__gte=offset, row_number__lt=stop)
|
results = queryset.filter(row_number__gt=offset, row_number__lt=stop)
|
||||||
|
|
||||||
# Adjust cursors based on the grouped results for pagination
|
# Adjust cursors based on the grouped results for pagination
|
||||||
next_cursor = Cursor(
|
next_cursor = Cursor(
|
||||||
@ -227,6 +224,8 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
|||||||
page > 0,
|
page > 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
count = queryset.count()
|
||||||
|
|
||||||
# Optionally, calculate the total count and max_hits if needed
|
# Optionally, calculate the total count and max_hits if needed
|
||||||
# This might require adjustments based on specific use cases
|
# This might require adjustments based on specific use cases
|
||||||
max_hits = math.ceil(
|
max_hits = math.ceil(
|
||||||
@ -243,7 +242,7 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
|||||||
results=results,
|
results=results,
|
||||||
next=next_cursor,
|
next=next_cursor,
|
||||||
prev=prev_cursor,
|
prev=prev_cursor,
|
||||||
hits=None,
|
hits=count,
|
||||||
max_hits=max_hits,
|
max_hits=max_hits,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -417,6 +416,7 @@ class BasePaginator:
|
|||||||
response = Response(
|
response = Response(
|
||||||
{
|
{
|
||||||
"grouped_by": group_by_field_name,
|
"grouped_by": group_by_field_name,
|
||||||
|
"total_count": (cursor_result.hits),
|
||||||
"next_cursor": str(cursor_result.next),
|
"next_cursor": str(cursor_result.next),
|
||||||
"prev_cursor": str(cursor_result.prev),
|
"prev_cursor": str(cursor_result.prev),
|
||||||
"next_page_results": cursor_result.next.has_results,
|
"next_page_results": cursor_result.next.has_results,
|
||||||
|
Loading…
Reference in New Issue
Block a user