Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
f8b7d5fa
Commit
f8b7d5fa
authored
Feb 04, 2013
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
have timer redirect when it expires
parent
1685f302
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
28 deletions
+41
-28
lms/djangoapps/courseware/views.py
+13
-3
lms/templates/courseware/testcenter_exam.html
+28
-25
No files found.
lms/djangoapps/courseware/views.py
View file @
f8b7d5fa
...
@@ -8,7 +8,7 @@ from django.core.context_processors import csrf
...
@@ -8,7 +8,7 @@ from django.core.context_processors import csrf
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
Http404
from
django.http
import
Http404
,
HttpResponseRedirect
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie
#from django.views.decorators.csrf import ensure_csrf_cookie
...
@@ -397,6 +397,12 @@ def timed_exam(request, course_id, chapter, section):
...
@@ -397,6 +397,12 @@ def timed_exam(request, course_id, chapter, section):
context
[
'content'
]
=
section_module
.
get_html
()
context
[
'content'
]
=
section_module
.
get_html
()
# determine where to go when the exam ends:
if
'time_expired_redirect_url'
not
in
section_descriptor
.
metadata
:
raise
Http404
time_expired_redirect_url
=
section_descriptor
.
metadata
.
get
(
'time_expired_redirect_url'
)
context
[
'time_expired_redirect_url'
]
=
time_expired_redirect_url
# figure out when the timed exam should end. Going forward, this is determined by getting a "normal"
# figure out when the timed exam should end. Going forward, this is determined by getting a "normal"
# duration from the test, then doing some math to modify the duration based on accommodations,
# duration from the test, then doing some math to modify the duration based on accommodations,
# and then use that value as the end. Once we have calculated this, it should be sticky -- we
# and then use that value as the end. Once we have calculated this, it should be sticky -- we
...
@@ -407,7 +413,7 @@ def timed_exam(request, course_id, chapter, section):
...
@@ -407,7 +413,7 @@ def timed_exam(request, course_id, chapter, section):
if
'duration'
not
in
section_descriptor
.
metadata
:
if
'duration'
not
in
section_descriptor
.
metadata
:
raise
Http404
raise
Http404
duration
=
int
(
section_descriptor
.
metadata
.
get
(
'duration'
))
duration
=
int
(
section_descriptor
.
metadata
.
get
(
'duration'
))
# get corresponding time module, if one is present:
# get corresponding time module, if one is present:
# TODO: determine what to use for module_key...
# TODO: determine what to use for module_key...
try
:
try
:
...
@@ -424,7 +430,11 @@ def timed_exam(request, course_id, chapter, section):
...
@@ -424,7 +430,11 @@ def timed_exam(request, course_id, chapter, section):
# Proposal: store URL in the section descriptor,
# Proposal: store URL in the section descriptor,
# along with the duration. If no such URL is set,
# along with the duration. If no such URL is set,
# just put up the error page,
# just put up the error page,
raise
Exception
(
"Time expired on {}"
.
format
(
timed_module
))
if
time_expired_redirect_url
is
None
:
raise
Exception
(
"Time expired on {}"
.
format
(
timed_module
))
else
:
return
HttpResponseRedirect
(
time_expired_redirect_url
)
elif
not
timed_module
.
has_begun
:
elif
not
timed_module
.
has_begun
:
# user has not started the exam, but may have an accommodation
# user has not started the exam, but may have an accommodation
# that has been granted to them.
# that has been granted to them.
...
...
lms/templates/courseware/testcenter_exam.html
View file @
f8b7d5fa
...
@@ -61,26 +61,21 @@
...
@@ -61,26 +61,21 @@
</script>
</script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
function
getRemainingTime
(){
var
timer
=
{
function
pretty_time_string
(
num
)
{
timer_inst
:
null
,
return
(
num
<
10
?
"0"
:
""
)
+
num
;
get_remaining_secs
:
function
()
{
}
// set the end time when the template is rendered.
// set the end time when the template is rendered.
// This value should be UTC time as number of milliseconds since epoch.
// This value should be UTC time as number of milliseconds since epoch.
var
endTime
=
new
Date
(
$
{
end_date
});
var
endTime
=
new
Date
(
$
{
end_date
});
var
currentTime
=
new
Date
();
var
currentTime
=
new
Date
();
var
remaining_secs
=
Math
.
floor
((
endTime
-
currentTime
)
/
1000
);
var
remaining_secs
=
Math
.
floor
((
endTime
-
currentTime
)
/
1000
);
return
remaining_secs
;
// check to see if time has expired. If so, we need
},
// to go to the exit URL.
get_time_string
:
function
()
{
// TBD...
function
pretty_time_string
(
num
)
{
if
(
remaining_secs
<=
0
)
{
return
(
num
<
10
?
"0"
:
""
)
+
num
;
return
"00:00:00"
;
// do we just set window.location =
<
url
>
value
?
}
}
// count down in terms of hours, minutes, and seconds:
// count down in terms of hours, minutes, and seconds:
var
hours
=
pretty_time_string
(
Math
.
floor
(
remaining_secs
/
3600
));
var
hours
=
pretty_time_string
(
Math
.
floor
(
remaining_secs
/
3600
));
remaining_secs
=
remaining_secs
%
3600
;
remaining_secs
=
remaining_secs
%
3600
;
...
@@ -90,17 +85,25 @@
...
@@ -90,17 +85,25 @@
var
remainingTimeString
=
hours
+
":"
+
minutes
+
":"
+
seconds
;
var
remainingTimeString
=
hours
+
":"
+
minutes
+
":"
+
seconds
;
return
remainingTimeString
;
return
remainingTimeString
;
}
},
update_time
:
function
(
self
)
{
setInterval
(
function
(){
remaining_secs
=
self
.
get_remaining_secs
();
$
(
'#exam_timer'
).
text
(
getRemainingTime
());
},
1000
);
if
(
remaining_secs
<=
0
)
{
self
.
end
(
self
);
}
// presumably we need to call something to clear the interval once
$
(
'#exam_timer'
).
text
(
self
.
get_time_string
(
remaining_secs
));
// the time has expired? Pass the object that the setInterval() returns
},
// to clearInterval()
start
:
function
()
{
var
that
=
this
;
this
.
timer_inst
=
setInterval
(
function
(){
that
.
update_time
(
that
);
},
1000
);
},
end
:
function
(
self
)
{
clearInterval
(
self
.
timer_inst
);
// redirect to specified URL:
window
.
location
=
"${time_expired_redirect_url}"
;
}
}
// start timer right away:
timer
.
start
();
</script>
</script>
</
%
block>
</
%
block>
...
...
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