diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 4712bbe..8692a96 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -180,6 +180,7 @@ class CourseFields(object): has_children = True checklists = List(scope=Scope.settings) info_sidebar_name = String(scope=Scope.settings, default='Course Handouts') + display_timezone = Boolean(help="True if timezones should be displayed on dates in the courseware", scope=Scope.settings, default=True) # An extra property is used rather than the wiki_slug/number because # there are courses that change the number for different runs. This allows diff --git a/common/lib/xmodule/xmodule/tests/test_date_utils.py b/common/lib/xmodule/xmodule/tests/test_date_utils.py index de00410..441f653 100644 --- a/common/lib/xmodule/xmodule/tests/test_date_utils.py +++ b/common/lib/xmodule/xmodule/tests/test_date_utils.py @@ -17,6 +17,10 @@ def test_get_default_time_display(): test_time = time.struct_time((1992, 3, 12, 15, 3, 30, 1, 71, 0)) assert_equals("Mar 12, 1992 at 15:03 UTC", date_utils.get_default_time_display(test_time)) + assert_equals("Mar 12, 1992 at 15:03 UTC", + date_utils.get_default_time_display(test_time, True)) + assert_equals("Mar 12, 1992 at 15:03", + date_utils.get_default_time_display(test_time, False)) def test_time_to_datetime(): diff --git a/common/lib/xmodule/xmodule/util/date_utils.py b/common/lib/xmodule/xmodule/util/date_utils.py index 601c4ce..e8b386d 100644 --- a/common/lib/xmodule/xmodule/util/date_utils.py +++ b/common/lib/xmodule/xmodule/util/date_utils.py @@ -2,15 +2,18 @@ import time import datetime -def get_default_time_display(time_struct): +def get_default_time_display(time_struct, display_timezone=True): """ Converts a time struct to a string representation. This is the default representation used in Studio and LMS. - It is of the form "Apr 09, 2013 at 16:00 UTC". + It is of the form "Apr 09, 2013 at 16:00" or "Apr 09, 2013 at 16:00 UTC" + depending on the value of display_timezone. - If None is passed in, an empty string will be returned. + If None is passed in for time_struct, an empty string will be returned. + The default value of display_timezone is True. """ - return get_time_struct_display(time_struct, "%b %d, %Y at %H:%M UTC") + timezone = " UTC" if display_timezone else "" + return get_time_struct_display(time_struct, "%b %d, %Y at %H:%M") + timezone def get_time_struct_display(time_struct, format): diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index ae15b40..a6aaa0c 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -12,7 +12,6 @@ from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponse, 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 from django_future.csrf import ensure_csrf_cookie from django.views.decorators.cache import cache_control @@ -67,9 +66,9 @@ def user_groups(user): @ensure_csrf_cookie @cache_if_anonymous def courses(request): - ''' + """ Render "find courses" page. The course selection work is done in courseware.courses. - ''' + """ courses = get_courses(request.user, request.META.get('HTTP_HOST')) courses = sort_by_announcement(courses) @@ -77,14 +76,16 @@ def courses(request): def render_accordion(request, course, chapter, section, model_data_cache): - ''' Draws navigation bar. Takes current position in accordion as - parameter. + """ + Draws navigation bar. Takes current position in accordion as + parameter. - If chapter and section are '' or None, renders a default accordion. + If chapter and section are '' or None, renders a default accordion. - course, chapter, and section are the url_names. + course, chapter, and section are the url_names. - Returns the html string''' + Returns the html string + """ # grab the table of contents user = User.objects.prefetch_related("groups").get(id=request.user.id) @@ -92,7 +93,8 @@ def render_accordion(request, course, chapter, section, model_data_cache): context = dict([('toc', toc), ('course_id', course.id), - ('csrf', csrf(request)['csrf_token'])] + template_imports.items()) + ('csrf', csrf(request)['csrf_token']), + ('display_timezone', course.display_timezone)] + template_imports.items()) return render_to_string('courseware/accordion.html', context) @@ -166,10 +168,10 @@ def save_child_position(seq_module, child_name): def check_for_active_timelimit_module(request, course_id, course): - ''' + """ Looks for a timing module for the given user and course that is currently active. If found, returns a context dict with timer-related values to enable display of time remaining. - ''' + """ context = {} # TODO (cpennington): Once we can query the course structure, replace this with such a query @@ -201,11 +203,11 @@ def check_for_active_timelimit_module(request, course_id, course): def update_timelimit_module(user, course_id, model_data_cache, timelimit_descriptor, timelimit_module): - ''' + """ 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_duration' in dict if timer is still active, and not if timer has expired. - ''' + """ context = {} # determine where to go when the exam ends: if timelimit_descriptor.time_expired_redirect_url is None: @@ -391,14 +393,14 @@ def index(request, course_id, chapter=None, section=None, @ensure_csrf_cookie def jump_to(request, course_id, location): - ''' + """ Show the page that contains a specific location. If the location is invalid or not in any class, return a 404. Otherwise, delegates to the index view to figure out whether this user has access, and what they should see. - ''' + """ # Complain if the location isn't valid try: location = Location(location) @@ -486,7 +488,9 @@ def syllabus(request, course_id): def registered_for_course(course, user): - '''Return CourseEnrollment if user is registered for course, else False''' + """ + Return CourseEnrollment if user is registered for course, else False + """ if user is None: return False if user.is_authenticated(): diff --git a/lms/templates/courseware/accordion.html b/lms/templates/courseware/accordion.html index da774a4..759ae61 100644 --- a/lms/templates/courseware/accordion.html +++ b/lms/templates/courseware/accordion.html @@ -11,7 +11,7 @@ <li class="${'active' if 'active' in section and section['active'] else ''} ${'graded' if 'graded' in section and section['graded'] else ''}"> <a href="${reverse('courseware_section', args=[course_id, chapter['url_name'], section['url_name']])}"> <p>${section['display_name']}</p> - <p class="subtitle">${section['format']} ${"due " + get_default_time_display(section['due']) if section.get('due') is not None else ''}</p> + <p class="subtitle">${section['format']} ${"due " + get_default_time_display(section['due'], display_timezone) if section.get('due') is not None else ''}</p> </a> </li> % endfor diff --git a/lms/templates/courseware/progress.html b/lms/templates/courseware/progress.html index 9e2a2e5..52d4203 100644 --- a/lms/templates/courseware/progress.html +++ b/lms/templates/courseware/progress.html @@ -64,7 +64,7 @@ ${progress_graph.body(grade_summary, course.grade_cutoffs, "grade-detail-graph", %if section.get('due') is not None: <em> - due ${get_default_time_display(section['due'])} + due ${get_default_time_display(section['due'], course.display_timezone)} </em> %endif </p>