dev: fix order by for pagination

This commit is contained in:
pablohashescobar 2024-03-22 20:58:08 +05:30
parent b4416b9172
commit 3f19326c2c
8 changed files with 39 additions and 15 deletions

View File

@ -890,7 +890,11 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -213,7 +213,11 @@ class IssueArchiveViewSet(BaseViewSet):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -213,7 +213,11 @@ class IssueListEndpoint(BaseAPIView):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -200,7 +200,11 @@ class IssueDraftViewSet(BaseViewSet):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -614,7 +614,11 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -259,7 +259,11 @@ class GlobalViewIssuesViewSet(BaseViewSet):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -663,7 +663,11 @@ class ProjectIssuesPublicEndpoint(BaseAPIView):
else:
# List Paginate
return self.paginate(
order_by=order_by_param,
order_by=(
"-priority_order"
if order_by_param in ["priority", "-priority"]
else order_by_param
),
request=request,
queryset=issue_queryset,
on_results=lambda issues: issue_on_results(

View File

@ -6,9 +6,9 @@ from collections.abc import Sequence
# Django imports
from django.db.models import Count, F, Window
from django.db.models.functions import RowNumber
from rest_framework.exceptions import ParseError
# Third party imports
from rest_framework.exceptions import ParseError
from rest_framework.response import Response
# Module imports
@ -115,7 +115,9 @@ class OffsetPaginator:
queryset = self.queryset
if self.key:
queryset = queryset.order_by(*self.key)
queryset = queryset.order_by(
*self.key,
)
page = cursor.offset
offset = cursor.offset * cursor.value
@ -506,12 +508,6 @@ class SubGroupedOffsetPaginator(OffsetPaginator):
for group in self.group_by_fields
}
def __result_already_added(self, result, group):
for existing_issue in group:
if existing_issue["id"] == result["id"]:
return True
return False
def __query_multi_grouper(self, results):
processed_results = self.__get_field_dict()
# Preparing a dict to keep track of group IDs associated with each label ID