Don't show course start date if it hasn't been set.
If neither start nor advertised_start has been changed from default don't show the course start date. This allows us to accept course registrations for courses whose start date is yet TBD.
This commit is contained in:
@@ -821,6 +821,10 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
|
||||
|
||||
@property
|
||||
def start_date_text(self):
|
||||
"""
|
||||
Returns the desired text corresponding the course's start date. Prefers .advertised_start,
|
||||
then falls back to .start
|
||||
"""
|
||||
def try_parse_iso_8601(text):
|
||||
try:
|
||||
result = Date().from_json(text)
|
||||
@@ -835,12 +839,22 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
|
||||
|
||||
if isinstance(self.advertised_start, basestring):
|
||||
return try_parse_iso_8601(self.advertised_start)
|
||||
elif self.advertised_start is None and self.start is None:
|
||||
# TODO this is an impossible state since the init function forces start to have a value
|
||||
return 'TBD'
|
||||
elif self.start_date_is_still_default:
|
||||
_ = self.runtime.service(self, "i18n").ugettext
|
||||
# Translators: TBD stands for 'To Be Determined' and is used when a course
|
||||
# does not yet have an announced start date.
|
||||
return _('TBD')
|
||||
else:
|
||||
return (self.advertised_start or self.start).strftime("%b %d, %Y")
|
||||
|
||||
@property
|
||||
def start_date_is_still_default(self):
|
||||
"""
|
||||
Checks if the start date set for the course is still default, i.e. .start has not been modified,
|
||||
and .advertised_start has not been set.
|
||||
"""
|
||||
return self.advertised_start is None and self.start == CourseFields.start.default
|
||||
|
||||
@property
|
||||
def end_date_text(self):
|
||||
"""
|
||||
|
||||
@@ -134,23 +134,29 @@ class IsNewCourseTestCase(unittest.TestCase):
|
||||
print "Comparing %s to %s" % (a, b)
|
||||
assertion(a_score, b_score)
|
||||
|
||||
start_advertised_settings = [
|
||||
# start, advertised, result, is_still_default
|
||||
('2012-12-02T12:00', None, 'Dec 02, 2012', False),
|
||||
('2012-12-02T12:00', '2011-11-01T12:00', 'Nov 01, 2011', False),
|
||||
('2012-12-02T12:00', 'Spring 2012', 'Spring 2012', False),
|
||||
('2012-12-02T12:00', 'November, 2011', 'November, 2011', False),
|
||||
(xmodule.course_module.CourseFields.start.default, None, 'TBD', True),
|
||||
(xmodule.course_module.CourseFields.start.default, 'January 2014', 'January 2014', False),
|
||||
]
|
||||
|
||||
@patch('xmodule.course_module.datetime.now')
|
||||
def test_start_date_text(self, gmtime_mock):
|
||||
gmtime_mock.return_value = NOW
|
||||
|
||||
settings = [
|
||||
# start, advertized, result
|
||||
('2012-12-02T12:00', None, 'Dec 02, 2012'),
|
||||
('2012-12-02T12:00', '2011-11-01T12:00', 'Nov 01, 2011'),
|
||||
('2012-12-02T12:00', 'Spring 2012', 'Spring 2012'),
|
||||
('2012-12-02T12:00', 'November, 2011', 'November, 2011'),
|
||||
]
|
||||
|
||||
for s in settings:
|
||||
for s in self.start_advertised_settings:
|
||||
d = get_dummy_course(start=s[0], advertised_start=s[1])
|
||||
print "Checking start=%s advertised=%s" % (s[0], s[1])
|
||||
self.assertEqual(d.start_date_text, s[2])
|
||||
|
||||
def test_start_date_is_default(self):
|
||||
for s in self.start_advertised_settings:
|
||||
d = get_dummy_course(start=s[0], advertised_start=s[1])
|
||||
self.assertEqual(d.start_date_is_still_default, s[3])
|
||||
|
||||
def test_display_organization(self):
|
||||
descriptor = get_dummy_course(start='2012-12-02T12:00', is_new=True)
|
||||
self.assertNotEqual(descriptor.location.org, descriptor.display_org_with_default)
|
||||
|
||||
Reference in New Issue
Block a user