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
edx
edx-proctoring
Commits
617db2b2
Commit
617db2b2
authored
Aug 23, 2015
by
chrisndodge
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #89 from edx/cdodge/detect-timer-manipulation
add computed remaining time to the API result set
parents
5ab7121e
a0b4621f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
edx_proctoring/utils.py
+20
-0
edx_proctoring/views.py
+11
-11
No files found.
edx_proctoring/utils.py
View file @
617db2b2
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
Helpers for the HTTP APIs
Helpers for the HTTP APIs
"""
"""
import
pytz
from
datetime
import
datetime
,
timedelta
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.authentication
import
SessionAuthentication
from
rest_framework.authentication
import
SessionAuthentication
...
@@ -16,6 +19,23 @@ class AuthenticatedAPIView(APIView):
...
@@ -16,6 +19,23 @@ class AuthenticatedAPIView(APIView):
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,)
def
get_time_remaining_for_attempt
(
attempt
):
"""
Returns the remaining time (in seconds) on an attempt
"""
# need to adjust for allowances
expires_at
=
attempt
[
'started_at'
]
+
timedelta
(
minutes
=
attempt
[
'allowed_time_limit_mins'
])
now_utc
=
datetime
.
now
(
pytz
.
UTC
)
if
expires_at
>
now_utc
:
time_remaining_seconds
=
(
expires_at
-
now_utc
)
.
seconds
else
:
time_remaining_seconds
=
0
return
time_remaining_seconds
def
humanized_time
(
time_in_minutes
):
def
humanized_time
(
time_in_minutes
):
"""
"""
Converts the given value in minutes to a more human readable format
Converts the given value in minutes to a more human readable format
...
...
edx_proctoring/views.py
View file @
617db2b2
...
@@ -4,7 +4,7 @@ Proctored Exams HTTP-based API endpoints
...
@@ -4,7 +4,7 @@ Proctored Exams HTTP-based API endpoints
import
logging
import
logging
import
pytz
import
pytz
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -40,7 +40,7 @@ from edx_proctoring.exceptions import (
...
@@ -40,7 +40,7 @@ from edx_proctoring.exceptions import (
from
edx_proctoring.serializers
import
ProctoredExamSerializer
,
ProctoredExamStudentAttemptSerializer
from
edx_proctoring.serializers
import
ProctoredExamSerializer
,
ProctoredExamStudentAttemptSerializer
from
edx_proctoring.models
import
ProctoredExamStudentAttemptStatus
,
ProctoredExamStudentAttempt
from
edx_proctoring.models
import
ProctoredExamStudentAttemptStatus
,
ProctoredExamStudentAttempt
from
.utils
import
AuthenticatedAPIView
from
.utils
import
AuthenticatedAPIView
,
get_time_remaining_for_attempt
ATTEMPTS_PER_PAGE
=
25
ATTEMPTS_PER_PAGE
=
25
...
@@ -264,7 +264,9 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
...
@@ -264,7 +264,9 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
attempt_id
=
attempt_id
attempt_id
=
attempt_id
)
)
)
)
raise
StudentExamAttemptDoesNotExistsException
(
err_msg
)
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
# make sure the the attempt belongs to the calling user_id
# make sure the the attempt belongs to the calling user_id
if
attempt
[
'user'
][
'id'
]
!=
request
.
user
.
id
:
if
attempt
[
'user'
][
'id'
]
!=
request
.
user
.
id
:
...
@@ -289,6 +291,11 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
...
@@ -289,6 +291,11 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
ProctoredExamStudentAttemptStatus
.
error
ProctoredExamStudentAttemptStatus
.
error
)
)
# add in the computed time remaining as a helper to a client app
time_remaining_seconds
=
get_time_remaining_for_attempt
(
attempt
)
attempt
[
'time_remaining_seconds'
]
=
time_remaining_seconds
return
Response
(
return
Response
(
data
=
attempt
,
data
=
attempt
,
status
=
status
.
HTTP_200_OK
status
=
status
.
HTTP_200_OK
...
@@ -449,14 +456,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
...
@@ -449,14 +456,7 @@ class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
exam
=
exam_info
[
'exam'
]
exam
=
exam_info
[
'exam'
]
attempt
=
exam_info
[
'attempt'
]
attempt
=
exam_info
[
'attempt'
]
# need to adjust for allowances
time_remaining_seconds
=
get_time_remaining_for_attempt
(
attempt
)
expires_at
=
attempt
[
'started_at'
]
+
timedelta
(
minutes
=
attempt
[
'allowed_time_limit_mins'
])
now_utc
=
datetime
.
now
(
pytz
.
UTC
)
if
expires_at
>
now_utc
:
time_remaining_seconds
=
(
expires_at
-
now_utc
)
.
seconds
else
:
time_remaining_seconds
=
0
proctoring_settings
=
getattr
(
settings
,
'PROCTORING_SETTINGS'
,
{})
proctoring_settings
=
getattr
(
settings
,
'PROCTORING_SETTINGS'
,
{})
low_threshold_pct
=
proctoring_settings
.
get
(
'low_threshold_pct'
,
.
2
)
low_threshold_pct
=
proctoring_settings
.
get
(
'low_threshold_pct'
,
.
2
)
...
...
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