Пример #1
0
    def summary(self, request):
        """
        Supports `date` param to specify the month.
        """
        query = request.query_params

        date = get_date(request, 'date', True)
        start, end = month_range(date.year, date.month)

        qs = Worklog.objects.filter(
            work_date__gte=start,
            work_date__lte=end,
        ).select_related('user')

        if 'user' in query:
            qs = qs.filter(user__in=query.getlist('user'))

        worklogs = list(qs)
        users = {
            worklog.user
            for worklog in worklogs
        }

        return Response(
            MonthlySummarySerializer(MonthlySummaryInput(
                [start, end],
                worklogs,
                'worklogs' in query,
                user,
            )).data for user in users
        )
Пример #2
0
    def monthly_summary(self, request, pk=None):
        """
        Supports `date` param to specify the month.
        """
        date = get_date(request, 'date', True)
        start, end = month_range(date.year, date.month)

        worklogs = list(Worklog.objects.filter(
            user_id=pk,
            work_date__gte=start,
            work_date__lte=end,
        ).select_related('user'))
        serializer = MonthlySummarySerializer(
            MonthlySummaryInput(
                [start, end],
                worklogs,
                'worklogs' in request.query_params,
                worklogs[0].user
            )
        )

        return Response(serializer.data)
Пример #3
0
    def monthly_worklog(self, date, username=None):
        start, end = month_range(date.year, date.month)

        return self.tempo_worklog({"username": username or self.current_user(), "dateFrom": start, "dateTo": end})