forked from github/plane
fix: recent pages endpoint (#640)
* fix: recent pages endpoint for date * fix: order by
This commit is contained in:
parent
448f383ec9
commit
15ce3537ad
@ -1,6 +1,5 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime, date
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
@ -226,7 +225,6 @@ class CreateIssueFromPageBlockEndpoint(BaseAPIView):
|
|||||||
verb="created",
|
verb="created",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
page_block.issue = issue
|
page_block.issue = issue
|
||||||
page_block.save()
|
page_block.save()
|
||||||
|
|
||||||
@ -256,12 +254,12 @@ class RecentPagesEndpoint(BaseAPIView):
|
|||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
)
|
)
|
||||||
current_time = timezone.now()
|
current_time = date.today()
|
||||||
day_before = current_time - timedelta(days=1)
|
day_before = current_time - timedelta(days=1)
|
||||||
|
|
||||||
todays_pages = (
|
todays_pages = (
|
||||||
Page.objects.filter(
|
Page.objects.filter(
|
||||||
updated_at__date=timezone.now().date(),
|
updated_at__date=date.today(),
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
)
|
)
|
||||||
@ -280,12 +278,12 @@ class RecentPagesEndpoint(BaseAPIView):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("-is_favorite", "-updated_by")
|
.order_by("-is_favorite", "-updated_at")
|
||||||
)
|
)
|
||||||
|
|
||||||
yesterdays_pages = (
|
yesterdays_pages = (
|
||||||
Page.objects.filter(
|
Page.objects.filter(
|
||||||
updated_at__date=day_before.date(),
|
updated_at__date=day_before,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
)
|
)
|
||||||
@ -304,14 +302,14 @@ class RecentPagesEndpoint(BaseAPIView):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("-is_favorite", "-updated_by")
|
.order_by("-is_favorite", "-updated_at")
|
||||||
)
|
)
|
||||||
|
|
||||||
earlier_this_week = (
|
earlier_this_week = (
|
||||||
Page.objects.filter(
|
Page.objects.filter(
|
||||||
updated_at__date__range=(
|
updated_at__date__range=(
|
||||||
(timezone.now() - timedelta(days=7)).date(),
|
(timezone.now() - timedelta(days=7)),
|
||||||
(timezone.now() - timedelta(days=2)).date(),
|
(timezone.now() - timedelta(days=2)),
|
||||||
),
|
),
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
@ -332,7 +330,7 @@ class RecentPagesEndpoint(BaseAPIView):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by("-is_favorite", "-updated_by")
|
.order_by("-is_favorite", "-updated_at")
|
||||||
)
|
)
|
||||||
todays_pages_serializer = PageSerializer(todays_pages, many=True)
|
todays_pages_serializer = PageSerializer(todays_pages, many=True)
|
||||||
yesterday_pages_serializer = PageSerializer(yesterdays_pages, many=True)
|
yesterday_pages_serializer = PageSerializer(yesterdays_pages, many=True)
|
||||||
@ -346,7 +344,7 @@ class RecentPagesEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
capture_exception(e)
|
print(e)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Something went wrong please try again later"},
|
{"error": "Something went wrong please try again later"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
Loading…
Reference in New Issue
Block a user