Commit b6ae62e3 by Brian Talbot

pearson - checking in files Brian W. worked on to resolve weird git issue locally

parents 1923ae0d f8b7d5fa
......@@ -8,7 +8,7 @@ from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
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 mitxmako.shortcuts import render_to_response, render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie
......@@ -397,6 +397,12 @@ def timed_exam(request, course_id, chapter, section):
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"
# 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
......@@ -407,7 +413,7 @@ def timed_exam(request, course_id, chapter, section):
if 'duration' not in section_descriptor.metadata:
raise Http404
duration = int(section_descriptor.metadata.get('duration'))
# get corresponding time module, if one is present:
# TODO: determine what to use for module_key...
try:
......@@ -424,7 +430,11 @@ def timed_exam(request, course_id, chapter, section):
# Proposal: store URL in the section descriptor,
# along with the duration. If no such URL is set,
# 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:
# user has not started the exam, but may have an accommodation
# that has been granted to them.
......
......@@ -61,26 +61,21 @@
</script>
<script type="text/javascript">
function getRemainingTime(){
function pretty_time_string(num) {
return ( num < 10 ? "0" : "" ) + num;
}
var timer = {
timer_inst : null,
get_remaining_secs : function() {
// set the end time when the template is rendered.
// This value should be UTC time as number of milliseconds since epoch.
var endTime = new Date(${end_date});
var currentTime = new Date();
var remaining_secs = Math.floor((endTime - currentTime)/1000);
// check to see if time has expired. If so, we need
// to go to the exit URL.
// TBD...
if (remaining_secs <= 0) {
return "00:00:00";
// do we just set window.location = <url> value?
return remaining_secs;
},
get_time_string : function() {
function pretty_time_string(num) {
return ( num < 10 ? "0" : "" ) + num;
}
// count down in terms of hours, minutes, and seconds:
var hours = pretty_time_string(Math.floor(remaining_secs / 3600));
remaining_secs = remaining_secs % 3600;
......@@ -90,17 +85,25 @@
var remainingTimeString = hours + ":" + minutes + ":" + seconds;
return remainingTimeString;
}
setInterval(function(){
$('#exam_timer').text(getRemainingTime()); }, 1000);
// presumably we need to call something to clear the interval once
// the time has expired? Pass the object that the setInterval() returns
// to clearInterval()
},
update_time : function(self) {
remaining_secs = self.get_remaining_secs();
if (remaining_secs <= 0) {
self.end(self);
}
$('#exam_timer').text(self.get_time_string(remaining_secs));
},
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>
</%block>
......
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