Commit c76d282c by Afzal Wali Committed by Muhammad Shoaib

search attempts url and view

parent 295142d5
......@@ -361,6 +361,12 @@ def get_all_exam_attempts(course_id):
exam_attempts = ProctoredExamStudentAttempt.get_all_exam_attempts(course_id)
return [ProctoredExamStudentAttemptSerializer(active_exam).data for active_exam in exam_attempts]
def get_filtered_exam_attempts(course_id, search_by):
"""
returns all exam attempts for a course id filtered by the search_by string in user names and emails.
"""
exam_attempts = ProctoredExamStudentAttempt.get_all_exam_attempts(course_id)
return [ProctoredExamStudentAttemptSerializer(active_exam).data for active_exam in exam_attempts]
def get_active_exams_for_user(user_id, course_id=None):
"""
......
......@@ -41,6 +41,11 @@ urlpatterns = patterns( # pylint: disable=invalid-name
name='edx_proctoring.proctored_exam.attempt'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt/course_id/{}/search/(?P<search_by>.+)$'.format(settings.COURSE_ID_PATTERN),
views.StudentProctoredExamAttemptCollection.as_view(),
name='edx_proctoring.proctored_exam.attempt.search'
),
url(
r'edx_proctoring/v1/proctored_exam/attempt$',
views.StudentProctoredExamAttemptCollection.as_view(),
name='edx_proctoring.proctored_exam.attempt.collection'
......
......@@ -30,7 +30,7 @@ from edx_proctoring.api import (
get_exam_attempt_by_id,
get_all_exam_attempts,
remove_exam_attempt_by_id,
)
get_filtered_exam_attempts)
from edx_proctoring.exceptions import (
ProctoredBaseException,
ProctoredExamNotFoundException,
......@@ -388,12 +388,17 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
return the status of the exam attempt
"""
def get(self, request, course_id=None): # pylint: disable=unused-argument
def get(self, request, course_id=None, search_by=None): # pylint: disable=unused-argument
"""
HTTP GET Handler. Returns the status of the exam attempt.
"""
if course_id is not None:
exam_attempts = get_all_exam_attempts(course_id)
if search_by is not None:
exam_attempts = get_filtered_exam_attempts(course_id, search_by)
attempt_url = reverse('edx_proctoring.proctored_exam.attempt.search', args=[course_id, search_by])
else:
exam_attempts = get_all_exam_attempts(course_id)
attempt_url = reverse('edx_proctoring.proctored_exam.attempt', args=[course_id])
# TODO have to change the default attempts per page
paginator = Paginator(exam_attempts, 1) # Show 1 attempts per page
......@@ -415,7 +420,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
'current_page': exam_attempts_page.number,
'total_pages': exam_attempts_page.paginator.num_pages,
},
'attempt_url': reverse('edx_proctoring.proctored_exam.attempt', args=[course_id])
'attempt_url': attempt_url
}
return Response(
......
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