Commit d8b5c979 by Muhammad Shoaib

added the new endpoint for the proctored exams in the course

parent a4a1775e
...@@ -104,6 +104,34 @@ def get_exam_by_id(exam_id): ...@@ -104,6 +104,34 @@ def get_exam_by_id(exam_id):
return serialized_exam_object.data return serialized_exam_object.data
def get_exams_by_course_id(course_id):
"""
Looks up exam by the course_id. Raises exception if not found.
Returns a list containing dictionary version of the Django ORM object
e.g.
[{
"course_id": "edX/DemoX/Demo_Course",
"content_id": "123",
"external_id": "",
"exam_name": "Midterm",
"time_limit_mins": 90,
"is_proctored": true,
"is_active": true
},
{
...: ...,
...: ...
},
..
]
"""
proctored_exams = ProctoredExam.get_exams_by_course_id(course_id)
serialized_proctored_exams = [ProctoredExamSerializer(proctored_exam).data for proctored_exam in proctored_exams]
return serialized_proctored_exams
def get_exam_by_content_id(course_id, content_id): def get_exam_by_content_id(course_id, content_id):
""" """
Looks up exam by the course_id/content_id pair. Raises exception if not found. Looks up exam by the course_id/content_id pair. Raises exception if not found.
......
...@@ -44,6 +44,14 @@ class ProctoredExam(TimeStampedModel): ...@@ -44,6 +44,14 @@ class ProctoredExam(TimeStampedModel):
db_table = 'proctoring_proctoredexam' db_table = 'proctoring_proctoredexam'
@classmethod @classmethod
def get_exams_by_course_id(cls, course_id):
"""
Returns the list of proctored exams
"""
return cls.objects.filter(course_id=course_id)
@classmethod
def get_exam_by_content_id(cls, course_id, content_id): def get_exam_by_content_id(cls, course_id, content_id):
""" """
Returns the Proctored Exam if found else returns None, Returns the Proctored Exam if found else returns None,
......
...@@ -25,6 +25,12 @@ urlpatterns = patterns( # pylint: disable=invalid-name ...@@ -25,6 +25,12 @@ urlpatterns = patterns( # pylint: disable=invalid-name
name='edx_proctoring.proctored_exam.exam_by_content_id' name='edx_proctoring.proctored_exam.exam_by_content_id'
), ),
url( url(
r'edx_proctoring/v1/proctored_exam/exam/course_id/{}$'.format(
settings.COURSE_ID_PATTERN),
views.ProctoredExamView.as_view(),
name='edx_proctoring.proctored_exam.exams_by_course_id'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt$', r'edx_proctoring/v1/proctored_exam/attempt$',
views.StudentProctoredExamAttempt.as_view(), views.StudentProctoredExamAttempt.as_view(),
name='edx_proctoring.proctored_exam.attempt' name='edx_proctoring.proctored_exam.attempt'
......
...@@ -21,7 +21,7 @@ from edx_proctoring.api import ( ...@@ -21,7 +21,7 @@ from edx_proctoring.api import (
remove_allowance_for_user, remove_allowance_for_user,
get_active_exams_for_user, get_active_exams_for_user,
create_exam_attempt, create_exam_attempt,
get_allowances_for_course) get_allowances_for_course, get_exams_by_course_id)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredBaseException, ProctoredBaseException,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -176,17 +176,24 @@ class ProctoredExamView(AuthenticatedAPIView): ...@@ -176,17 +176,24 @@ class ProctoredExamView(AuthenticatedAPIView):
data={"detail": "The exam_id does not exist."} data={"detail": "The exam_id does not exist."}
) )
else: else:
# get by course_id & content_id if course_id is not None:
try: if content_id is not None:
return Response( # get by course_id & content_id
data=get_exam_by_content_id(course_id, content_id), try:
status=status.HTTP_200_OK return Response(
) data=get_exam_by_content_id(course_id, content_id),
except ProctoredExamNotFoundException: status=status.HTTP_200_OK
return Response( )
status=status.HTTP_400_BAD_REQUEST, except ProctoredExamNotFoundException:
data={"detail": "The exam with course_id, content_id does not exist."} return Response(
) status=status.HTTP_400_BAD_REQUEST,
data={"detail": "The exam with course_id, content_id does not exist."}
)
else:
result_set = get_exams_by_course_id(
course_id=course_id
)
return Response(result_set)
class StudentProctoredExamAttempt(AuthenticatedAPIView): class StudentProctoredExamAttempt(AuthenticatedAPIView):
......
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