From b5378b04b3402db5c99aaeaf3db456bbd8c5e684 Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Tue, 12 Feb 2013 12:25:11 -0500 Subject: [PATCH] change timer to calculate relative duration in javascript --- .../lib/xmodule/xmodule/timelimit_module.py | 4 ++-- lms/djangoapps/courseware/views.py | 19 +++++++++---------- lms/templates/courseware/courseware.html | 17 +++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/common/lib/xmodule/xmodule/timelimit_module.py b/common/lib/xmodule/xmodule/timelimit_module.py index 23ed06eb59..9abb5d183f 100644 --- a/common/lib/xmodule/xmodule/timelimit_module.py +++ b/common/lib/xmodule/xmodule/timelimit_module.py @@ -86,8 +86,8 @@ class TimeLimitModule(XModule): modified_duration = self._get_accommodated_duration(duration) self.ending_at = self.beginning_at + modified_duration - def get_end_time_in_ms(self): - return int(self.ending_at * 1000) + def get_remaining_time_in_ms(self): + return int((self.ending_at - time()) * 1000) def get_instance_state(self): state = {} diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index e8b36ecd2a..fb351e1c01 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -177,10 +177,10 @@ def check_for_active_timelimit_module(request, course_id, course): raise Http404("No {0} metadata at this location: {1} ".format('time_expired_redirect_url', location)) time_expired_redirect_url = timelimit_descriptor.metadata.get('time_expired_redirect_url') context['time_expired_redirect_url'] = time_expired_redirect_url - # Fetch the end time (in GMT) as stored in the module when it was started. - # This value should be UTC time as number of milliseconds since epoch. - end_date = timelimit_module.get_end_time_in_ms() - context['timer_expiration_datetime'] = end_date + # Fetch the remaining time relative to the end time as stored in the module when it was started. + # This value should be in milliseconds. + remaining_time = timelimit_module.get_remaining_time_in_ms() + context['timer_expiration_duration'] = remaining_time if 'suppress_toplevel_navigation' in timelimit_descriptor.metadata: context['suppress_toplevel_navigation'] = timelimit_descriptor.metadata['suppress_toplevel_navigation'] return_url = reverse('jump_to', kwargs={'course_id':course_id, 'location':location}) @@ -191,7 +191,7 @@ def update_timelimit_module(user, course_id, student_module_cache, timelimit_des ''' Updates the state of the provided timing module, starting it if it hasn't begun. Returns dict with timer-related values to enable display of time remaining. - Returns 'timer_expiration_datetime' in dict if timer is still active, and not if timer has expired. + Returns 'timer_expiration_duration' in dict if timer is still active, and not if timer has expired. ''' context = {} # determine where to go when the exam ends: @@ -215,10 +215,9 @@ def update_timelimit_module(user, course_id, student_module_cache, timelimit_des instance_module.save() # the exam has been started, either because the student is returning to the - # exam page, or because they have just visited it. Fetch the end time (in GMT) as stored - # in the module when it was started. - # This value should be UTC time as number of milliseconds since epoch. - context['timer_expiration_datetime'] = timelimit_module.get_end_time_in_ms() + # exam page, or because they have just visited it. Fetch the remaining time relative to the + # end time as stored in the module when it was started. + context['timer_expiration_duration'] = timelimit_module.get_remaining_time_in_ms() # also use the timed module to determine whether top-level navigation is visible: if 'suppress_toplevel_navigation' in timelimit_descriptor.metadata: context['suppress_toplevel_navigation'] = timelimit_descriptor.metadata['suppress_toplevel_navigation'] @@ -325,7 +324,7 @@ def index(request, course_id, chapter=None, section=None, if section_module.category == 'timelimit': timer_context = update_timelimit_module(request.user, course_id, student_module_cache, section_descriptor, section_module) - if 'timer_expiration_datetime' in timer_context: + if 'timer_expiration_duration' in timer_context: context.update(timer_context) else: # if there is no expiration defined, then we know the timer has expired: diff --git a/lms/templates/courseware/courseware.html b/lms/templates/courseware/courseware.html index 72a4b2cae1..fcbc83d815 100644 --- a/lms/templates/courseware/courseware.html +++ b/lms/templates/courseware/courseware.html @@ -60,14 +60,12 @@ }); -% if timer_expiration_datetime: +% if timer_expiration_duration: