Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-proctoring
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
edx-proctoring
Commits
7c13841d
Commit
7c13841d
authored
Jul 17, 2015
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add status check in case attempt expired
parent
dd9d8b51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
4 deletions
+43
-4
edx_proctoring/api.py
+43
-4
No files found.
edx_proctoring/api.py
View file @
7c13841d
...
...
@@ -168,13 +168,53 @@ def remove_allowance_for_user(exam_id, user_id, key):
student_allowance
.
delete
()
def
_update_exam_attempt_status
(
attempt
):
"""
Helper method to see if the status of an
exam needs to be updated, e.g. timeout
"""
if
not
attempt
:
return
attempt
# right now the only adjustment to
# status is transitioning to timeout
has_started_exam
=
(
attempt
and
attempt
.
get
(
'started_at'
)
and
attempt
.
get
(
'status'
)
==
ProctoredExamStudentAttemptStatus
.
started
)
if
has_started_exam
:
now_utc
=
datetime
.
now
(
pytz
.
UTC
)
expires_at
=
attempt
[
'started_at'
]
+
timedelta
(
minutes
=
attempt
[
'allowed_time_limit_mins'
])
has_time_expired
=
now_utc
>
expires_at
if
has_time_expired
:
exam_attempt_obj
=
ProctoredExamStudentAttempt
.
objects
.
get_exam_attempt_by_id
(
attempt
[
'id'
])
exam_attempt_obj
.
status
=
ProctoredExamStudentAttemptStatus
.
timed_out
exam_attempt_obj
.
save
()
attempt
=
ProctoredExamStudentAttemptSerializer
(
exam_attempt_obj
)
.
data
return
attempt
def
_get_exam_attempt
(
exam_attempt_obj
):
"""
Helper method to commonalize the two query patterns
"""
serialized_attempt_obj
=
ProctoredExamStudentAttemptSerializer
(
exam_attempt_obj
)
attempt
=
serialized_attempt_obj
.
data
if
exam_attempt_obj
else
None
attempt
=
_update_exam_attempt_status
(
attempt
)
return
attempt
def
get_exam_attempt
(
exam_id
,
user_id
):
"""
Return an existing exam attempt for the given student
"""
exam_attempt_obj
=
ProctoredExamStudentAttempt
.
objects
.
get_exam_attempt
(
exam_id
,
user_id
)
serialized_attempt_obj
=
ProctoredExamStudentAttemptSerializer
(
exam_attempt_obj
)
return
serialized_attempt_obj
.
data
if
exam_attempt_obj
else
None
return
_get_exam_attempt
(
exam_attempt_obj
)
def
get_exam_attempt_by_id
(
attempt_id
):
...
...
@@ -182,8 +222,7 @@ def get_exam_attempt_by_id(attempt_id):
Return an existing exam attempt for the given student
"""
exam_attempt_obj
=
ProctoredExamStudentAttempt
.
objects
.
get_exam_attempt_by_id
(
attempt_id
)
serialized_attempt_obj
=
ProctoredExamStudentAttemptSerializer
(
exam_attempt_obj
)
return
serialized_attempt_obj
.
data
if
exam_attempt_obj
else
None
return
_get_exam_attempt
(
exam_attempt_obj
)
def
update_exam_attempt
(
attempt_id
,
**
kwargs
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment