Skip to content

Commit

Permalink
Show all timelogs (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Jan 31, 2024
1 parent 4f02d06 commit eaea78e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions timesheet/api_views/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,25 @@ def get_permissions(self):
return [permission() for permission in permission_classes]


MAX_TIMELOGS = 20


class TimesheetViewSet(viewsets.ViewSet):
"""
A ViewSet for listing time logs
"""
permission_classes = [IsAuthenticated]

def list(self, request):

today = convert_time_to_user_timezone(
timezone.now(), request.user.profile.timezone)
start_of_week = today - timedelta(days=today.weekday())
start_of_last_week = start_of_week - timedelta(days=7)

queryset = Timelog.objects.filter(
user=self.request.user,
start_time__gte=start_of_last_week,
start_time__lt=start_of_week + timedelta(days=7)
).order_by('-start_time')
serializer = TimelogSerializer(queryset, many=True)
serializer = TimelogSerializer(queryset[:MAX_TIMELOGS], many=True)
return Response(serializer.data)


Expand Down

0 comments on commit eaea78e

Please sign in to comment.