From 0af2da2dfee88f6693be746df4fe4fe3b24cabf7 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Tue, 12 Mar 2024 19:33:46 +0530 Subject: [PATCH] chore: paginator changes --- apiserver/plane/app/views/cycle/base.py | 2 + apiserver/plane/app/views/dashboard/base.py | 78 ++++++++++--------- apiserver/plane/app/views/exporter/base.py | 13 ++-- apiserver/plane/app/views/issue/archive.py | 2 + apiserver/plane/app/views/issue/base.py | 4 + apiserver/plane/app/views/issue/draft.py | 2 + apiserver/plane/app/views/module/base.py | 2 + .../plane/app/views/notification/base.py | 26 ++++--- apiserver/plane/app/views/project/base.py | 49 ++++++------ apiserver/plane/app/views/user/base.py | 1 + apiserver/plane/app/views/view/base.py | 2 + apiserver/plane/app/views/workspace/user.py | 64 +++++++-------- 12 files changed, 133 insertions(+), 112 deletions(-) diff --git a/apiserver/plane/app/views/cycle/base.py b/apiserver/plane/app/views/cycle/base.py index 36d949f7c..ae7e378e0 100644 --- a/apiserver/plane/app/views/cycle/base.py +++ b/apiserver/plane/app/views/cycle/base.py @@ -798,6 +798,7 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -807,6 +808,7 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet): # Group paginate return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( diff --git a/apiserver/plane/app/views/dashboard/base.py b/apiserver/plane/app/views/dashboard/base.py index e6757faf9..e713db878 100644 --- a/apiserver/plane/app/views/dashboard/base.py +++ b/apiserver/plane/app/views/dashboard/base.py @@ -1,52 +1,53 @@ # 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.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.utils import timezone +from rest_framework import status # Third Party imports 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 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): @@ -562,6 +563,7 @@ def dashboard_recent_collaborators(self, request, slug): ) return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=project_members_with_activities, controller=self.get_results_controller, diff --git a/apiserver/plane/app/views/exporter/base.py b/apiserver/plane/app/views/exporter/base.py index 846508515..f882486ee 100644 --- a/apiserver/plane/app/views/exporter/base.py +++ b/apiserver/plane/app/views/exporter/base.py @@ -1,14 +1,14 @@ # Third Party imports -from rest_framework.response import Response 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 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): @@ -69,6 +69,7 @@ class ExportIssuesEndpoint(BaseAPIView): "cursor", False ): return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=exporter_history, on_results=lambda exporter_history: ExporterHistorySerializer( diff --git a/apiserver/plane/app/views/issue/archive.py b/apiserver/plane/app/views/issue/archive.py index 9a032954a..9dcc09479 100644 --- a/apiserver/plane/app/views/issue/archive.py +++ b/apiserver/plane/app/views/issue/archive.py @@ -125,6 +125,7 @@ class IssueArchiveViewSet(BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -134,6 +135,7 @@ class IssueArchiveViewSet(BaseViewSet): # Group paginate return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( diff --git a/apiserver/plane/app/views/issue/base.py b/apiserver/plane/app/views/issue/base.py index afabee142..d81071375 100644 --- a/apiserver/plane/app/views/issue/base.py +++ b/apiserver/plane/app/views/issue/base.py @@ -123,6 +123,7 @@ class IssueListEndpoint(BaseAPIView): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -132,6 +133,7 @@ class IssueListEndpoint(BaseAPIView): # Group paginate return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -238,6 +240,7 @@ class IssueViewSet(WebhookMixin, BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -248,6 +251,7 @@ class IssueViewSet(WebhookMixin, BaseViewSet): # Group paginate return self.paginate( request=request, + order_by=order_by_param, queryset=issue_queryset, on_results=lambda issues: issue_on_results( group_by=group_by, issues=issues diff --git a/apiserver/plane/app/views/issue/draft.py b/apiserver/plane/app/views/issue/draft.py index 530f75675..49f6bce7c 100644 --- a/apiserver/plane/app/views/issue/draft.py +++ b/apiserver/plane/app/views/issue/draft.py @@ -112,6 +112,7 @@ class IssueDraftViewSet(BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -121,6 +122,7 @@ class IssueDraftViewSet(BaseViewSet): # Group paginate return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( diff --git a/apiserver/plane/app/views/module/base.py b/apiserver/plane/app/views/module/base.py index 84d30640a..0f3d48fe4 100644 --- a/apiserver/plane/app/views/module/base.py +++ b/apiserver/plane/app/views/module/base.py @@ -524,6 +524,7 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -533,6 +534,7 @@ class ModuleIssueViewSet(WebhookMixin, BaseViewSet): # Group paginate return self.paginate( + order_by=order_by_param, request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( diff --git a/apiserver/plane/app/views/notification/base.py b/apiserver/plane/app/views/notification/base.py index 8dae618db..5af5d0a9a 100644 --- a/apiserver/plane/app/views/notification/base.py +++ b/apiserver/plane/app/views/notification/base.py @@ -1,26 +1,27 @@ # Django imports -from django.db.models import Q, OuterRef, Exists +from django.db.models import Exists, OuterRef, Q from django.utils import timezone # Third party imports from rest_framework import status 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 ( NotificationSerializer, 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): @@ -131,6 +132,7 @@ class NotificationViewSet(BaseViewSet, BasePaginator): "cursor", False ): return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=(notifications), on_results=lambda notifications: NotificationSerializer( diff --git a/apiserver/plane/app/views/project/base.py b/apiserver/plane/app/views/project/base.py index 5dbc99a27..51647884f 100644 --- a/apiserver/plane/app/views/project/base.py +++ b/apiserver/plane/app/views/project/base.py @@ -1,52 +1,50 @@ # Python imports import boto3 +from django.conf import settings # Django imports from django.db import IntegrityError from django.db.models import ( - Prefetch, - Q, Exists, - OuterRef, F, Func, + OuterRef, + Prefetch, + Q, Subquery, ) -from django.conf import settings +from rest_framework import serializers, status +from rest_framework.permissions import AllowAny # Third Party imports 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 ( ProjectBasePermission, 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 ( - Project, - ProjectMember, - Workspace, - State, - ProjectFavorite, - ProjectIdentifier, - Module, Cycle, Inbox, - ProjectDeployBoard, - IssueProperty, Issue, + IssueProperty, + Module, + Project, + ProjectDeployBoard, + ProjectFavorite, + ProjectIdentifier, + ProjectMember, + State, + Workspace, ) from plane.utils.cache import cache_response @@ -162,6 +160,7 @@ class ProjectViewSet(WebhookMixin, BaseViewSet): "cursor", False ): return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=(projects), on_results=lambda projects: ProjectListSerializer( diff --git a/apiserver/plane/app/views/user/base.py b/apiserver/plane/app/views/user/base.py index 4d69d1cf2..a466efff7 100644 --- a/apiserver/plane/app/views/user/base.py +++ b/apiserver/plane/app/views/user/base.py @@ -183,6 +183,7 @@ class UserActivityEndpoint(BaseAPIView, BasePaginator): ).select_related("actor", "workspace", "issue", "project") return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=queryset, on_results=lambda issue_activities: IssueActivitySerializer( diff --git a/apiserver/plane/app/views/view/base.py b/apiserver/plane/app/views/view/base.py index 0215b0c9e..6733b6a2d 100644 --- a/apiserver/plane/app/views/view/base.py +++ b/apiserver/plane/app/views/view/base.py @@ -166,6 +166,7 @@ class GlobalViewIssuesViewSet(BaseViewSet): # List Paginate if not group_by: return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( @@ -175,6 +176,7 @@ class GlobalViewIssuesViewSet(BaseViewSet): # Group paginate return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=issue_queryset, on_results=lambda issues: issue_on_results( diff --git a/apiserver/plane/app/views/workspace/user.py b/apiserver/plane/app/views/workspace/user.py index 36b00b738..6566b2b42 100644 --- a/apiserver/plane/app/views/workspace/user.py +++ b/apiserver/plane/app/views/workspace/user.py @@ -1,60 +1,61 @@ # Python imports from datetime import date + 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 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 from rest_framework import status from rest_framework.response import Response +from plane.app.permissions import ( + WorkspaceEntityPermission, + WorkspaceViewerPermission, +) + # Module imports from plane.app.serializers import ( - WorkSpaceSerializer, - ProjectMemberSerializer, IssueActivitySerializer, IssueSerializer, + ProjectMemberSerializer, + WorkSpaceSerializer, WorkspaceUserPropertiesSerializer, ) from plane.app.views.base import BaseAPIView from plane.db.models import ( - User, - Workspace, - ProjectMember, - IssueActivity, + CycleIssue, Issue, - IssueLink, + IssueActivity, IssueAttachment, + IssueLink, IssueSubscriber, Project, + ProjectMember, + User, + Workspace, WorkspaceMember, - CycleIssue, WorkspaceUserProperties, ) -from plane.app.permissions import ( - WorkspaceEntityPermission, - WorkspaceViewerPermission, -) from plane.utils.issue_filters import issue_filters @@ -394,6 +395,7 @@ class WorkspaceUserActivityEndpoint(BaseAPIView): queryset = queryset.filter(project__in=projects) return self.paginate( + order_by=request.GET.get("order_by", "-created_at"), request=request, queryset=queryset, on_results=lambda issue_activities: IssueActivitySerializer(