chore: paginator changes

This commit is contained in:
pablohashescobar 2024-03-12 19:33:46 +05:30
parent 26ec7323e5
commit 0af2da2dfe
12 changed files with 133 additions and 112 deletions

View File

@ -798,6 +798,7 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -807,6 +808,7 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(

View File

@ -1,52 +1,53 @@
# Django imports # Django imports
from django.db.models import (
Q,
Case,
When,
Value,
CharField,
Count,
F,
Exists,
OuterRef,
Subquery,
JSONField,
Func,
Prefetch,
IntegerField,
)
from django.contrib.postgres.aggregates import ArrayAgg from django.contrib.postgres.aggregates import ArrayAgg
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from django.db.models import UUIDField from django.db.models import (
Case,
CharField,
Count,
Exists,
F,
Func,
IntegerField,
JSONField,
OuterRef,
Prefetch,
Q,
Subquery,
UUIDField,
Value,
When,
)
from django.db.models.functions import Coalesce from django.db.models.functions import Coalesce
from django.utils import timezone from django.utils import timezone
from rest_framework import status
# Third Party imports # Third Party imports
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status
from plane.app.serializers import (
DashboardSerializer,
IssueActivitySerializer,
IssueSerializer,
WidgetSerializer,
)
from plane.db.models import (
Dashboard,
DashboardWidget,
Issue,
IssueActivity,
IssueAttachment,
IssueLink,
IssueRelation,
Project,
ProjectMember,
User,
Widget,
)
from plane.utils.issue_filters import issue_filters
# Module imports # Module imports
from .. import BaseAPIView from .. import BaseAPIView
from plane.db.models import (
Issue,
IssueActivity,
ProjectMember,
Widget,
DashboardWidget,
Dashboard,
Project,
IssueLink,
IssueAttachment,
IssueRelation,
User,
)
from plane.app.serializers import (
IssueActivitySerializer,
IssueSerializer,
DashboardSerializer,
WidgetSerializer,
)
from plane.utils.issue_filters import issue_filters
def dashboard_overview_stats(self, request, slug): def dashboard_overview_stats(self, request, slug):
@ -562,6 +563,7 @@ def dashboard_recent_collaborators(self, request, slug):
) )
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=project_members_with_activities, queryset=project_members_with_activities,
controller=self.get_results_controller, controller=self.get_results_controller,

View File

@ -1,14 +1,14 @@
# Third Party imports # Third Party imports
from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from rest_framework.response import Response
from plane.app.permissions import WorkSpaceAdminPermission
from plane.app.serializers import ExporterHistorySerializer
from plane.bgtasks.export_task import issue_export_task
from plane.db.models import ExporterHistory, Project, Workspace
# Module imports # Module imports
from .. import BaseAPIView from .. import BaseAPIView
from plane.app.permissions import WorkSpaceAdminPermission
from plane.bgtasks.export_task import issue_export_task
from plane.db.models import Project, ExporterHistory, Workspace
from plane.app.serializers import ExporterHistorySerializer
class ExportIssuesEndpoint(BaseAPIView): class ExportIssuesEndpoint(BaseAPIView):
@ -69,6 +69,7 @@ class ExportIssuesEndpoint(BaseAPIView):
"cursor", False "cursor", False
): ):
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=exporter_history, queryset=exporter_history,
on_results=lambda exporter_history: ExporterHistorySerializer( on_results=lambda exporter_history: ExporterHistorySerializer(

View File

@ -125,6 +125,7 @@ class IssueArchiveViewSet(BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -134,6 +135,7 @@ class IssueArchiveViewSet(BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(

View File

@ -123,6 +123,7 @@ class IssueListEndpoint(BaseAPIView):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -132,6 +133,7 @@ class IssueListEndpoint(BaseAPIView):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -238,6 +240,7 @@ class IssueViewSet(WebhookMixin, BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -248,6 +251,7 @@ class IssueViewSet(WebhookMixin, BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
request=request, request=request,
order_by=order_by_param,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
group_by=group_by, issues=issues group_by=group_by, issues=issues

View File

@ -112,6 +112,7 @@ class IssueDraftViewSet(BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -121,6 +122,7 @@ class IssueDraftViewSet(BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(

View File

@ -524,6 +524,7 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -533,6 +534,7 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=order_by_param,
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(

View File

@ -1,26 +1,27 @@
# Django imports # Django imports
from django.db.models import Q, OuterRef, Exists from django.db.models import Exists, OuterRef, Q
from django.utils import timezone from django.utils import timezone
# Third party imports # Third party imports
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from plane.utils.paginator import BasePaginator
# Module imports
from ..base import BaseViewSet, BaseAPIView
from plane.db.models import (
Notification,
IssueAssignee,
IssueSubscriber,
Issue,
WorkspaceMember,
UserNotificationPreference,
)
from plane.app.serializers import ( from plane.app.serializers import (
NotificationSerializer, NotificationSerializer,
UserNotificationPreferenceSerializer, UserNotificationPreferenceSerializer,
) )
from plane.db.models import (
Issue,
IssueAssignee,
IssueSubscriber,
Notification,
UserNotificationPreference,
WorkspaceMember,
)
from plane.utils.paginator import BasePaginator
# Module imports
from ..base import BaseAPIView, BaseViewSet
class NotificationViewSet(BaseViewSet, BasePaginator): class NotificationViewSet(BaseViewSet, BasePaginator):
@ -131,6 +132,7 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
"cursor", False "cursor", False
): ):
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=(notifications), queryset=(notifications),
on_results=lambda notifications: NotificationSerializer( on_results=lambda notifications: NotificationSerializer(

View File

@ -1,52 +1,50 @@
# Python imports # Python imports
import boto3 import boto3
from django.conf import settings
# Django imports # Django imports
from django.db import IntegrityError from django.db import IntegrityError
from django.db.models import ( from django.db.models import (
Prefetch,
Q,
Exists, Exists,
OuterRef,
F, F,
Func, Func,
OuterRef,
Prefetch,
Q,
Subquery, Subquery,
) )
from django.conf import settings from rest_framework import serializers, status
from rest_framework.permissions import AllowAny
# Third Party imports # Third Party imports
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status
from rest_framework import serializers
from rest_framework.permissions import AllowAny
# Module imports
from plane.app.views.base import BaseViewSet, BaseAPIView, WebhookMixin
from plane.app.serializers import (
ProjectSerializer,
ProjectListSerializer,
ProjectFavoriteSerializer,
ProjectDeployBoardSerializer,
)
from plane.app.permissions import ( from plane.app.permissions import (
ProjectBasePermission, ProjectBasePermission,
ProjectMemberPermission, ProjectMemberPermission,
) )
from plane.app.serializers import (
ProjectDeployBoardSerializer,
ProjectFavoriteSerializer,
ProjectListSerializer,
ProjectSerializer,
)
# Module imports
from plane.app.views.base import BaseAPIView, BaseViewSet, WebhookMixin
from plane.db.models import ( from plane.db.models import (
Project,
ProjectMember,
Workspace,
State,
ProjectFavorite,
ProjectIdentifier,
Module,
Cycle, Cycle,
Inbox, Inbox,
ProjectDeployBoard,
IssueProperty,
Issue, Issue,
IssueProperty,
Module,
Project,
ProjectDeployBoard,
ProjectFavorite,
ProjectIdentifier,
ProjectMember,
State,
Workspace,
) )
from plane.utils.cache import cache_response from plane.utils.cache import cache_response
@ -162,6 +160,7 @@ class ProjectViewSet(WebhookMixin, BaseViewSet):
"cursor", False "cursor", False
): ):
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=(projects), queryset=(projects),
on_results=lambda projects: ProjectListSerializer( on_results=lambda projects: ProjectListSerializer(

View File

@ -183,6 +183,7 @@ class UserActivityEndpoint(BaseAPIView, BasePaginator):
).select_related("actor", "workspace", "issue", "project") ).select_related("actor", "workspace", "issue", "project")
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=queryset, queryset=queryset,
on_results=lambda issue_activities: IssueActivitySerializer( on_results=lambda issue_activities: IssueActivitySerializer(

View File

@ -166,6 +166,7 @@ class GlobalViewIssuesViewSet(BaseViewSet):
# List Paginate # List Paginate
if not group_by: if not group_by:
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(
@ -175,6 +176,7 @@ class GlobalViewIssuesViewSet(BaseViewSet):
# Group paginate # Group paginate
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=issue_queryset, queryset=issue_queryset,
on_results=lambda issues: issue_on_results( on_results=lambda issues: issue_on_results(

View File

@ -1,60 +1,61 @@
# Python imports # Python imports
from datetime import date from datetime import date
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from django.contrib.postgres.aggregates import ArrayAgg
from django.contrib.postgres.fields import ArrayField
from django.db.models import (
Case,
CharField,
Count,
F,
Func,
IntegerField,
Max,
OuterRef,
Q,
UUIDField,
Value,
When,
)
from django.db.models.fields import DateField
from django.db.models.functions import Cast, Coalesce, ExtractWeek
# Django imports # Django imports
from django.utils import timezone from django.utils import timezone
from django.db.models import (
OuterRef,
Func,
F,
Q,
Count,
Case,
Value,
CharField,
When,
Max,
IntegerField,
UUIDField,
)
from django.db.models.functions import ExtractWeek, Cast
from django.db.models.fields import DateField
from django.contrib.postgres.aggregates import ArrayAgg
from django.contrib.postgres.fields import ArrayField
from django.db.models.functions import Coalesce
# Third party modules # Third party modules
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from plane.app.permissions import (
WorkspaceEntityPermission,
WorkspaceViewerPermission,
)
# Module imports # Module imports
from plane.app.serializers import ( from plane.app.serializers import (
WorkSpaceSerializer,
ProjectMemberSerializer,
IssueActivitySerializer, IssueActivitySerializer,
IssueSerializer, IssueSerializer,
ProjectMemberSerializer,
WorkSpaceSerializer,
WorkspaceUserPropertiesSerializer, WorkspaceUserPropertiesSerializer,
) )
from plane.app.views.base import BaseAPIView from plane.app.views.base import BaseAPIView
from plane.db.models import ( from plane.db.models import (
User, CycleIssue,
Workspace,
ProjectMember,
IssueActivity,
Issue, Issue,
IssueLink, IssueActivity,
IssueAttachment, IssueAttachment,
IssueLink,
IssueSubscriber, IssueSubscriber,
Project, Project,
ProjectMember,
User,
Workspace,
WorkspaceMember, WorkspaceMember,
CycleIssue,
WorkspaceUserProperties, WorkspaceUserProperties,
) )
from plane.app.permissions import (
WorkspaceEntityPermission,
WorkspaceViewerPermission,
)
from plane.utils.issue_filters import issue_filters from plane.utils.issue_filters import issue_filters
@ -394,6 +395,7 @@ class WorkspaceUserActivityEndpoint(BaseAPIView):
queryset = queryset.filter(project__in=projects) queryset = queryset.filter(project__in=projects)
return self.paginate( return self.paginate(
order_by=request.GET.get("order_by", "-created_at"),
request=request, request=request,
queryset=queryset, queryset=queryset,
on_results=lambda issue_activities: IssueActivitySerializer( on_results=lambda issue_activities: IssueActivitySerializer(