Fakultas Ilmu Komputer UI

Commit 77e1346f authored by Muzaki Azami's avatar Muzaki Azami

Merge branch 'adding-flag-for-user-weekly-report' into 'staging'

adding flag to get_weekly_report's JSON response

See merge request !81
parents 2cceb480 f4bb7218
Pipeline #83002 passed with stages
in 19 minutes and 41 seconds
......@@ -184,16 +184,16 @@ class WeeklyReportTest(APITestCase):
reports = WeeklyReport.objects.all()
serializer = WeeklyReportSerializer(reports, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.data, {'today_week': 0,'has_submitted_this_week':False,'data':serializer.data})
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_specific_weekly_report(self):
response = self.client.get("/progress/user_report/?client_id=" + str(self.custom_user_2.id))
reports = WeeklyReport.objects.filter(client=self.custom_user_2)
response = self.client.get("/progress/user_report/?client_id=" + str(self.custom_user_3.id))
reports = WeeklyReport.objects.filter(client=self.custom_user_3)
reports = reports.order_by('week_num')
serializer = WeeklyReportSerializer(reports, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.data, {'today_week': 1,'has_submitted_this_week':False,'data':serializer.data})
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_user_weekly_report_belonging_to_a_nutritionist(self):
......@@ -212,7 +212,7 @@ class WeeklyReportTest(APITestCase):
reports = reports.order_by('week_num')
serializer = WeeklyReportSerializer(reports, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.data, {'today_week': 1,'has_submitted_this_week':True,'data':serializer.data})
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_get_user_weekly_report_belonging_to_non_nutritionist(self):
......@@ -231,7 +231,7 @@ class WeeklyReportTest(APITestCase):
reports = reports.order_by('week_num')
serializer = WeeklyReportSerializer(reports, many=True)
self.assertEqual(response.data, serializer.data)
self.assertEqual(response.data, {'today_week': 1,'has_submitted_this_week':True,'data':serializer.data})
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_weekly_report_string(self):
......
......@@ -2,6 +2,7 @@ import datetime
from rest_framework import viewsets, status
from rest_framework.response import Response
from django.db.models import Q
from authentication.models import CustomUser
from authentication.utilities import get_appropriate_week_num
from .models import WeeklyReport, WeeklyReportComment
from .serializers import WeeklyReportSerializer, WeeklyReportCommentSerializer
......@@ -49,6 +50,25 @@ class WeeklyReportViewSet(viewsets.ModelViewSet):
return Response(response, status=status.HTTP_201_CREATED, headers=headers)
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
this_week_submission = False
week_number = 0
user_id = self.request.query_params.get('client_id')
if user_id is not None:
user = CustomUser.objects.get(Q(id=user_id))
u_deadline = user.deadline
week_number = get_appropriate_week_num(u_deadline)
has_this_week_report = queryset.filter(week_num = week_number)
if has_this_week_report:
this_week_submission = True
serializer = self.get_serializer(queryset, many=True)
return Response({\
'today_week':week_number,\
'has_submitted_this_week':this_week_submission,\
'data':serializer.data})
class WeeklyReportCommentViewSet(viewsets.ModelViewSet):
serializer_class = WeeklyReportCommentSerializer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment