chore: cycle current status (#3270)
* dev: cycle status * chore: cycle status logic updated --------- Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
This commit is contained in:
parent
1d5a3a02c1
commit
10ab081a0b
12 changed files with 63 additions and 66 deletions
|
|
@ -40,6 +40,7 @@ class CycleSerializer(BaseSerializer):
|
|||
started_estimates = serializers.IntegerField(read_only=True)
|
||||
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
|
||||
project_detail = ProjectLiteSerializer(read_only=True, source="project")
|
||||
status = serializers.CharField(read_only=True)
|
||||
|
||||
def validate(self, data):
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ from django.db.models import (
|
|||
Count,
|
||||
Prefetch,
|
||||
Sum,
|
||||
Case,
|
||||
When,
|
||||
Value,
|
||||
CharField
|
||||
)
|
||||
from django.core import serializers
|
||||
from django.utils import timezone
|
||||
|
|
@ -157,6 +161,28 @@ class CycleViewSet(WebhookMixin, BaseViewSet):
|
|||
),
|
||||
)
|
||||
)
|
||||
.annotate(
|
||||
status=Case(
|
||||
When(
|
||||
Q(start_date__lte=timezone.now()) & Q(end_date__gte=timezone.now()),
|
||||
then=Value("CURRENT")
|
||||
),
|
||||
When(
|
||||
start_date__gt=timezone.now(),
|
||||
then=Value("UPCOMING")
|
||||
),
|
||||
When(
|
||||
end_date__lt=timezone.now(),
|
||||
then=Value("COMPLETED")
|
||||
),
|
||||
When(
|
||||
Q(start_date__isnull=True) & Q(end_date__isnull=True),
|
||||
then=Value("DRAFT")
|
||||
),
|
||||
default=Value("DRAFT"),
|
||||
output_field=CharField(),
|
||||
)
|
||||
)
|
||||
.prefetch_related(
|
||||
Prefetch(
|
||||
"issue_cycle__issue__assignees",
|
||||
|
|
@ -177,7 +203,7 @@ class CycleViewSet(WebhookMixin, BaseViewSet):
|
|||
queryset = self.get_queryset()
|
||||
cycle_view = request.GET.get("cycle_view", "all")
|
||||
|
||||
queryset = queryset.order_by("-is_favorite","-created_at")
|
||||
queryset = queryset.order_by("-is_favorite", "-created_at")
|
||||
|
||||
# Current Cycle
|
||||
if cycle_view == "current":
|
||||
|
|
@ -575,7 +601,9 @@ class CycleIssueViewSet(WebhookMixin, BaseViewSet):
|
|||
)
|
||||
)
|
||||
|
||||
issues = IssueStateSerializer(issues, many=True, fields=fields if fields else None).data
|
||||
issues = IssueStateSerializer(
|
||||
issues, many=True, fields=fields if fields else None
|
||||
).data
|
||||
issue_dict = {str(issue["id"]): issue for issue in issues}
|
||||
return Response(issue_dict, status=status.HTTP_200_OK)
|
||||
|
||||
|
|
@ -805,4 +833,4 @@ class TransferCycleIssueEndpoint(BaseAPIView):
|
|||
updated_cycles, ["cycle_id"], batch_size=100
|
||||
)
|
||||
|
||||
return Response({"message": "Success"}, status=status.HTTP_200_OK)
|
||||
return Response({"message": "Success"}, status=status.HTTP_200_OK)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue