Commit 5a74232b by Afzal Wali

refactored all checks of status to the ProctoredExamStudentAttemptStatus class

parent d0977aad
...@@ -531,18 +531,8 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True, ...@@ -531,18 +531,8 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True,
# don't allow state transitions from a completed state to an incomplete state # don't allow state transitions from a completed state to an incomplete state
# if a re-attempt is desired then the current attempt must be deleted # if a re-attempt is desired then the current attempt must be deleted
# #
in_completed_status = exam_attempt_obj.status in [ in_completed_status = ProctoredExamStudentAttemptStatus.is_completed_status(exam_attempt_obj.status)
ProctoredExamStudentAttemptStatus.verified, ProctoredExamStudentAttemptStatus.rejected, to_incompleted_status = ProctoredExamStudentAttemptStatus.is_incomplete_status(to_status)
ProctoredExamStudentAttemptStatus.declined, ProctoredExamStudentAttemptStatus.not_reviewed,
ProctoredExamStudentAttemptStatus.submitted, ProctoredExamStudentAttemptStatus.error,
ProctoredExamStudentAttemptStatus.timed_out
]
to_incompleted_status = to_status in [
ProctoredExamStudentAttemptStatus.eligible, ProctoredExamStudentAttemptStatus.created,
ProctoredExamStudentAttemptStatus.ready_to_start, ProctoredExamStudentAttemptStatus.started,
ProctoredExamStudentAttemptStatus.ready_to_submit
]
if in_completed_status and to_incompleted_status: if in_completed_status and to_incompleted_status:
err_msg = ( err_msg = (
...@@ -562,13 +552,7 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True, ...@@ -562,13 +552,7 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True,
exam_attempt_obj.save() exam_attempt_obj.save()
# see if the status transition this changes credit requirement status # see if the status transition this changes credit requirement status
update_credit = to_status in [ if ProctoredExamStudentAttemptStatus.needs_credit_status_update(to_status):
ProctoredExamStudentAttemptStatus.verified, ProctoredExamStudentAttemptStatus.rejected,
ProctoredExamStudentAttemptStatus.declined, ProctoredExamStudentAttemptStatus.not_reviewed,
ProctoredExamStudentAttemptStatus.submitted, ProctoredExamStudentAttemptStatus.error
]
if update_credit:
# trigger credit workflow, as needed # trigger credit workflow, as needed
credit_service = get_runtime_service('credit') credit_service = get_runtime_service('credit')
...@@ -600,16 +584,11 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True, ...@@ -600,16 +584,11 @@ def update_attempt_status(exam_id, user_id, to_status, raise_if_not_found=True,
status=verification status=verification
) )
if cascade_effects: if cascade_effects and ProctoredExamStudentAttemptStatus.is_a_cascadable_failure(to_status):
# some state transitions (namely to a rejected or declined status) # some state transitions (namely to a rejected or declined status)
# will mark other exams as declined because once we fail or decline # will mark other exams as declined because once we fail or decline
# one exam all other (un-completed) proctored exams will be likewise # one exam all other (un-completed) proctored exams will be likewise
# updated to reflect a declined status # updated to reflect a declined status
cascade_failure = to_status in [
ProctoredExamStudentAttemptStatus.rejected,
ProctoredExamStudentAttemptStatus.declined
]
if cascade_failure:
# get all other unattempted exams and mark also as declined # get all other unattempted exams and mark also as declined
_exams = ProctoredExam.get_all_exams_for_course( _exams = ProctoredExam.get_all_exams_for_course(
exam_attempt_obj.proctored_exam.course_id, exam_attempt_obj.proctored_exam.course_id,
......
...@@ -147,6 +147,39 @@ class ProctoredExamStudentAttemptStatus(object): ...@@ -147,6 +147,39 @@ class ProctoredExamStudentAttemptStatus(object):
ProctoredExamStudentAttemptStatus.error ProctoredExamStudentAttemptStatus.error
] ]
@classmethod
def is_incomplete_status(cls, status):
"""
Returns a boolean if the passed in status is in an "incomplete" state.
"""
return status in [
ProctoredExamStudentAttemptStatus.eligible, ProctoredExamStudentAttemptStatus.created,
ProctoredExamStudentAttemptStatus.ready_to_start, ProctoredExamStudentAttemptStatus.started,
ProctoredExamStudentAttemptStatus.ready_to_submit
]
@classmethod
def needs_credit_status_update(cls, to_status):
"""
Returns a boolean if the passed in to_status calls for an update to the credit requirement status.
"""
return to_status in [
ProctoredExamStudentAttemptStatus.verified, ProctoredExamStudentAttemptStatus.rejected,
ProctoredExamStudentAttemptStatus.declined, ProctoredExamStudentAttemptStatus.not_reviewed,
ProctoredExamStudentAttemptStatus.submitted, ProctoredExamStudentAttemptStatus.error
]
@classmethod
def is_a_cascadable_failure(cls, to_status):
"""
Returns a boolean if the passed in to_status has a failure that needs to be cascaded
to other attempts.
"""
return to_status in [
ProctoredExamStudentAttemptStatus.rejected,
ProctoredExamStudentAttemptStatus.declined
]
class ProctoredExamStudentAttemptManager(models.Manager): class ProctoredExamStudentAttemptManager(models.Manager):
""" """
......
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