Commit e4dac6e3 by cahrens

Add display_timezone so course authors can choose not to display timezones in LMS.

parent f31588c8
...@@ -180,6 +180,7 @@ class CourseFields(object): ...@@ -180,6 +180,7 @@ class CourseFields(object):
has_children = True has_children = True
checklists = List(scope=Scope.settings) checklists = List(scope=Scope.settings)
info_sidebar_name = String(scope=Scope.settings, default='Course Handouts') 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 # An extra property is used rather than the wiki_slug/number because
# there are courses that change the number for different runs. This allows # there are courses that change the number for different runs. This allows
......
...@@ -17,6 +17,10 @@ def test_get_default_time_display(): ...@@ -17,6 +17,10 @@ def test_get_default_time_display():
test_time = time.struct_time((1992, 3, 12, 15, 3, 30, 1, 71, 0)) test_time = time.struct_time((1992, 3, 12, 15, 3, 30, 1, 71, 0))
assert_equals("Mar 12, 1992 at 15:03 UTC", assert_equals("Mar 12, 1992 at 15:03 UTC",
date_utils.get_default_time_display(test_time)) 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(): def test_time_to_datetime():
......
...@@ -2,15 +2,18 @@ import time ...@@ -2,15 +2,18 @@ import time
import datetime 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 Converts a time struct to a string representation. This is the default
representation used in Studio and LMS. 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): def get_time_struct_display(time_struct, format):
......
...@@ -12,7 +12,6 @@ from django.contrib.auth.decorators import login_required ...@@ -12,7 +12,6 @@ from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponse, HttpResponseRedirect from django.http import Http404, HttpResponse, 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_future.csrf import ensure_csrf_cookie from django_future.csrf import ensure_csrf_cookie
from django.views.decorators.cache import cache_control from django.views.decorators.cache import cache_control
...@@ -67,9 +66,9 @@ def user_groups(user): ...@@ -67,9 +66,9 @@ def user_groups(user):
@ensure_csrf_cookie @ensure_csrf_cookie
@cache_if_anonymous @cache_if_anonymous
def courses(request): def courses(request):
''' """
Render "find courses" page. The course selection work is done in courseware.courses. Render "find courses" page. The course selection work is done in courseware.courses.
''' """
courses = get_courses(request.user, request.META.get('HTTP_HOST')) courses = get_courses(request.user, request.META.get('HTTP_HOST'))
courses = sort_by_announcement(courses) courses = sort_by_announcement(courses)
...@@ -77,14 +76,16 @@ def courses(request): ...@@ -77,14 +76,16 @@ def courses(request):
def render_accordion(request, course, chapter, section, model_data_cache): 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 # grab the table of contents
user = User.objects.prefetch_related("groups").get(id=request.user.id) 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): ...@@ -92,7 +93,8 @@ def render_accordion(request, course, chapter, section, model_data_cache):
context = dict([('toc', toc), context = dict([('toc', toc),
('course_id', course.id), ('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) return render_to_string('courseware/accordion.html', context)
...@@ -166,10 +168,10 @@ def save_child_position(seq_module, child_name): ...@@ -166,10 +168,10 @@ def save_child_position(seq_module, child_name):
def check_for_active_timelimit_module(request, course_id, course): 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. 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. If found, returns a context dict with timer-related values to enable display of time remaining.
''' """
context = {} context = {}
# TODO (cpennington): Once we can query the course structure, replace this with such a query # 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): ...@@ -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): 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. 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 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. Returns 'timer_expiration_duration' in dict if timer is still active, and not if timer has expired.
''' """
context = {} context = {}
# determine where to go when the exam ends: # determine where to go when the exam ends:
if timelimit_descriptor.time_expired_redirect_url is None: if timelimit_descriptor.time_expired_redirect_url is None:
...@@ -391,14 +393,14 @@ def index(request, course_id, chapter=None, section=None, ...@@ -391,14 +393,14 @@ def index(request, course_id, chapter=None, section=None,
@ensure_csrf_cookie @ensure_csrf_cookie
def jump_to(request, course_id, location): def jump_to(request, course_id, location):
''' """
Show the page that contains a specific location. Show the page that contains a specific location.
If the location is invalid or not in any class, return a 404. 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 Otherwise, delegates to the index view to figure out whether this user
has access, and what they should see. has access, and what they should see.
''' """
# Complain if the location isn't valid # Complain if the location isn't valid
try: try:
location = Location(location) location = Location(location)
...@@ -486,7 +488,9 @@ def syllabus(request, course_id): ...@@ -486,7 +488,9 @@ def syllabus(request, course_id):
def registered_for_course(course, user): 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: if user is None:
return False return False
if user.is_authenticated(): if user.is_authenticated():
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<li class="${'active' if 'active' in section and section['active'] else ''} ${'graded' if 'graded' in section and section['graded'] else ''}"> <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']])}"> <a href="${reverse('courseware_section', args=[course_id, chapter['url_name'], section['url_name']])}">
<p>${section['display_name']}</p> <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> </a>
</li> </li>
% endfor % endfor
......
...@@ -64,7 +64,7 @@ ${progress_graph.body(grade_summary, course.grade_cutoffs, "grade-detail-graph", ...@@ -64,7 +64,7 @@ ${progress_graph.body(grade_summary, course.grade_cutoffs, "grade-detail-graph",
%if section.get('due') is not None: %if section.get('due') is not None:
<em> <em>
due ${get_default_time_display(section['due'])} due ${get_default_time_display(section['due'], course.display_timezone)}
</em> </em>
%endif %endif
</p> </p>
......
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