Allow custom formatting of due date strings.
STUD-724 Test course for allowing custom formatting of due date strings. STUD-724 Try making the name of the course match the folder name. More cleanup. More cleanup. updates.
This commit is contained in:
@@ -338,6 +338,10 @@ class CourseFields(object):
|
||||
])
|
||||
info_sidebar_name = String(scope=Scope.settings, default='Course Handouts')
|
||||
show_timezone = Boolean(help="True if timezones should be shown on dates in the courseware", scope=Scope.settings, default=True)
|
||||
due_date_display_format = String(
|
||||
help="Format supported by strftime for displaying due dates. Takes precedence over show_timezone.",
|
||||
scope=Scope.settings, default=None
|
||||
)
|
||||
enrollment_domain = String(help="External login method associated with user accounts allowed to register in course",
|
||||
scope=Scope.settings)
|
||||
course_image = String(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for xmodule.util.date_utils"""
|
||||
|
||||
from nose.tools import assert_equals, assert_false # pylint: disable=E0611
|
||||
from xmodule.util.date_utils import get_default_time_display, almost_same_datetime
|
||||
from xmodule.util.date_utils import get_default_time_display, get_time_display, almost_same_datetime
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
from pytz import UTC
|
||||
|
||||
@@ -33,6 +33,28 @@ def test_get_default_time_display_notz():
|
||||
get_default_time_display(test_time, False))
|
||||
|
||||
|
||||
def test_get_time_display_return_empty():
|
||||
assert_equals("", get_time_display(None))
|
||||
test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
|
||||
assert_equals("", get_time_display(test_time, ""))
|
||||
|
||||
|
||||
def test_get_time_display():
|
||||
test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
|
||||
assert_equals("dummy text", get_time_display(test_time, 'dummy text'))
|
||||
assert_equals("Mar 12 1992", get_time_display(test_time, '%b %d %Y', True))
|
||||
assert_equals("Mar 12 1992 UTC", get_time_display(test_time, '%b %d %Y %Z', False))
|
||||
assert_equals("Mar 12 15:03", get_time_display(test_time, '%b %d %H:%M', False))
|
||||
|
||||
|
||||
def test_get_time_pass_through():
|
||||
test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
|
||||
assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time))
|
||||
assert_equals("Mar 12, 1992 at 15:03", get_time_display(test_time, None, False))
|
||||
assert_equals("Mar 12, 1992 at 15:03", get_time_display(test_time, "%", False))
|
||||
assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time, "%", True))
|
||||
|
||||
|
||||
# pylint: disable=W0232
|
||||
class NamelessTZ(tzinfo):
|
||||
"""Static timezone for testing"""
|
||||
|
||||
@@ -30,6 +30,25 @@ def get_default_time_display(dt, show_timezone=True):
|
||||
at=_(u"at"), tz=timezone).strip()
|
||||
|
||||
|
||||
def get_time_display(dt, format_string=None, show_timezone=True):
|
||||
"""
|
||||
Converts a datetime to a string representation.
|
||||
|
||||
If None is passed in for dt, an empty string will be returned.
|
||||
If the format_string is None, or if format_string is improperly
|
||||
formatted, this method will return the value from `get_default_time_display`
|
||||
(passing in the show_timezone argument).
|
||||
If the format_string is specified, show_timezone is ignored.
|
||||
format_string should be a unicode string that is a valid argument for datetime's strftime method.
|
||||
"""
|
||||
if dt is None or format_string is None:
|
||||
return get_default_time_display(dt, show_timezone)
|
||||
try:
|
||||
return unicode(dt.strftime(format_string))
|
||||
except ValueError:
|
||||
return get_default_time_display(dt, show_timezone)
|
||||
|
||||
|
||||
def almost_same_datetime(dt1, dt2, allowed_delta=timedelta(minutes=1)):
|
||||
"""
|
||||
Returns true if these are w/in a minute of each other. (in case secs saved to db
|
||||
|
||||
Reference in New Issue
Block a user