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): ...@@ -361,6 +361,12 @@ def get_all_exam_attempts(course_id):
exam_attempts = ProctoredExamStudentAttempt.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] 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): def get_active_exams_for_user(user_id, course_id=None):
""" """
......
...@@ -41,6 +41,11 @@ urlpatterns = patterns( # pylint: disable=invalid-name ...@@ -41,6 +41,11 @@ urlpatterns = patterns( # pylint: disable=invalid-name
name='edx_proctoring.proctored_exam.attempt' name='edx_proctoring.proctored_exam.attempt'
), ),
url( 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$', r'edx_proctoring/v1/proctored_exam/attempt$',
views.StudentProctoredExamAttemptCollection.as_view(), views.StudentProctoredExamAttemptCollection.as_view(),
name='edx_proctoring.proctored_exam.attempt.collection' name='edx_proctoring.proctored_exam.attempt.collection'
......
...@@ -30,7 +30,7 @@ from edx_proctoring.api import ( ...@@ -30,7 +30,7 @@ from edx_proctoring.api import (
get_exam_attempt_by_id, get_exam_attempt_by_id,
get_all_exam_attempts, get_all_exam_attempts,
remove_exam_attempt_by_id, remove_exam_attempt_by_id,
) get_filtered_exam_attempts)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredBaseException, ProctoredBaseException,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -388,12 +388,17 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView): ...@@ -388,12 +388,17 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
return the status of the exam attempt 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. HTTP GET Handler. Returns the status of the exam attempt.
""" """
if course_id is not None: 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 # TODO have to change the default attempts per page
paginator = Paginator(exam_attempts, 1) # Show 1 attempts per page paginator = Paginator(exam_attempts, 1) # Show 1 attempts per page
...@@ -415,7 +420,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView): ...@@ -415,7 +420,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
'current_page': exam_attempts_page.number, 'current_page': exam_attempts_page.number,
'total_pages': exam_attempts_page.paginator.num_pages, '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( 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