Commit 7865e2fb by Diana Huang

Move certificates_show_before_end into a new variable

Mark it as deprecated, but maintain backwards compatibility.

ECOM-11
parent 0d62895b
...@@ -54,7 +54,7 @@ class CourseEndingTest(TestCase): ...@@ -54,7 +54,7 @@ class CourseEndingTest(TestCase):
def test_cert_info(self): def test_cert_info(self):
user = Mock(username="fred") user = Mock(username="fred")
survey_url = "http://a_survey.com" survey_url = "http://a_survey.com"
course = Mock(end_of_course_survey_url=survey_url, certificates_show_before_end=False) course = Mock(end_of_course_survey_url=survey_url, certificates_display_behavior='end')
self.assertEqual(_cert_info(user, course, None), self.assertEqual(_cert_info(user, course, None),
{'status': 'processing', {'status': 'processing',
...@@ -133,21 +133,14 @@ class CourseEndingTest(TestCase): ...@@ -133,21 +133,14 @@ class CourseEndingTest(TestCase):
'mode': 'honor' 'mode': 'honor'
}) })
# test when the status is true, we get the correct results out # test when the display is unavailable or notpassing, we get the correct results out
course2.certificates_show_before_end = True course2.certificates_display_behavior = 'early_no_info'
cert_status = {'status': 'unavailable'} cert_status = {'status': 'unavailable'}
self.assertIsNone(_cert_info(user, course2, cert_status)) self.assertIsNone(_cert_info(user, course2, cert_status))
cert_status = {'status': 'notpassing', 'grade': '67', cert_status = {'status': 'notpassing', 'grade': '67',
'download_url': download_url, 'mode': 'honor'} 'download_url': download_url, 'mode': 'honor'}
self.assertEqual(_cert_info(user, course2, cert_status), self.assertIsNone(_cert_info(user, course2, cert_status))
{'status': 'notpassing',
'show_disabled_download_button': False,
'show_download_url': False,
'show_survey_button': False,
'grade': '67',
'mode': 'honor'
})
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
......
...@@ -285,7 +285,9 @@ def _cert_info(user, course, cert_status): ...@@ -285,7 +285,9 @@ def _cert_info(user, course, cert_status):
if cert_status is None: if cert_status is None:
return default_info return default_info
if cert_status['status'] == 'unavailable' and course.certificates_show_before_end: is_hidden_status = cert_status['status'] in ('unavailable', 'processing', 'generating', 'notpassing')
if course.certificates_display_behavior == 'early_no_info' and is_hidden_status:
return None return None
status = template_state.get(cert_status['status'], default_status) status = template_state.get(cert_status['status'], default_status)
......
...@@ -219,8 +219,8 @@ class CourseFields(object): ...@@ -219,8 +219,8 @@ class CourseFields(object):
scope=Scope.settings scope=Scope.settings
) )
display_name = String( display_name = String(
help=_("Enter the name of the course as it should appear in the edX.org course list."), help=_("Enter the name of the course as it should appear in the edX.org course list."),
default="Empty", default="Empty",
display_name=_("Course Display Name"), display_name=_("Course Display Name"),
scope=Scope.settings scope=Scope.settings
) )
...@@ -452,7 +452,15 @@ class CourseFields(object): ...@@ -452,7 +452,15 @@ class CourseFields(object):
display_name=_("Certificates Downloadable Before End"), display_name=_("Certificates Downloadable Before End"),
help=_("Enter true or false. If true, students can download certificates before the course ends, if they've met certificate requirements."), help=_("Enter true or false. If true, students can download certificates before the course ends, if they've met certificate requirements."),
scope=Scope.settings, scope=Scope.settings,
default=False default=False,
deprecated=True
)
certificates_display_behavior = String(
display_name=_("Certificates Display Behavior"),
help=_("Has three possible states: 'end', 'early_with_info', 'early_no_info'. 'end' is the default behavior, where certificates will only appear after a course has ended. 'early_with_info' will display all certificate information before a course has ended. 'early_no_info' will hide all certificate information unless a student has earned a certificate."),
scope=Scope.settings,
default="end"
) )
course_image = String( course_image = String(
display_name=_("Course About Page Image"), display_name=_("Course About Page Image"),
...@@ -711,7 +719,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): ...@@ -711,7 +719,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
""" """
Return True if it is acceptable to show the student a certificate download link Return True if it is acceptable to show the student a certificate download link
""" """
return self.certificates_show_before_end or self.has_ended() show_early = self.certificates_display_behavior in ('early_with_info', 'early_no_info') or self.certificates_show_before_end
return show_early or self.has_ended()
def has_started(self): def has_started(self):
return datetime.now(UTC()) > self.start return datetime.now(UTC()) > self.start
......
...@@ -49,7 +49,7 @@ class DummySystem(ImportSystem): ...@@ -49,7 +49,7 @@ class DummySystem(ImportSystem):
) )
def get_dummy_course(start, announcement=None, is_new=None, advertised_start=None, end=None, certs=False): def get_dummy_course(start, announcement=None, is_new=None, advertised_start=None, end=None, certs='end'):
"""Get a dummy course""" """Get a dummy course"""
system = DummySystem(load_error_modules=True) system = DummySystem(load_error_modules=True)
...@@ -70,7 +70,7 @@ def get_dummy_course(start, announcement=None, is_new=None, advertised_start=Non ...@@ -70,7 +70,7 @@ def get_dummy_course(start, announcement=None, is_new=None, advertised_start=Non
{is_new} {is_new}
{advertised_start} {advertised_start}
{end} {end}
certificates_show_before_end="{certs}"> certificates_display_behavior="{certs}">
<chapter url="hi" url_name="ch" display_name="CH"> <chapter url="hi" url_name="ch" display_name="CH">
<html url_name="h" display_name="H">Two houses, ...</html> <html url_name="h" display_name="H">Two houses, ...</html>
</chapter> </chapter>
...@@ -100,10 +100,12 @@ class HasEndedMayCertifyTestCase(unittest.TestCase): ...@@ -100,10 +100,12 @@ class HasEndedMayCertifyTestCase(unittest.TestCase):
#""".format(org=ORG, course=COURSE) #""".format(org=ORG, course=COURSE)
past_end = (datetime.now() - timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00") past_end = (datetime.now() - timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00")
future_end = (datetime.now() + timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00") future_end = (datetime.now() + timedelta(days=12)).strftime("%Y-%m-%dT%H:%M:00")
self.past_show_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs=True) self.past_show_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs='early_with_info')
self.past_noshow_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs=False) self.past_show_certs_no_info = get_dummy_course("2012-01-01T12:00", end=past_end, certs='early_no_info')
self.future_show_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs=True) self.past_noshow_certs = get_dummy_course("2012-01-01T12:00", end=past_end, certs='end')
self.future_noshow_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs=False) self.future_show_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs='early_with_info')
self.future_show_certs_no_info = get_dummy_course("2012-01-01T12:00", end=future_end, certs='early_no_info')
self.future_noshow_certs = get_dummy_course("2012-01-01T12:00", end=future_end, certs='end')
#self.past_show_certs = system.process_xml(sample_xml.format(end=past_end, cert=True)) #self.past_show_certs = system.process_xml(sample_xml.format(end=past_end, cert=True))
#self.past_noshow_certs = system.process_xml(sample_xml.format(end=past_end, cert=False)) #self.past_noshow_certs = system.process_xml(sample_xml.format(end=past_end, cert=False))
#self.future_show_certs = system.process_xml(sample_xml.format(end=future_end, cert=True)) #self.future_show_certs = system.process_xml(sample_xml.format(end=future_end, cert=True))
...@@ -112,15 +114,19 @@ class HasEndedMayCertifyTestCase(unittest.TestCase): ...@@ -112,15 +114,19 @@ class HasEndedMayCertifyTestCase(unittest.TestCase):
def test_has_ended(self): def test_has_ended(self):
"""Check that has_ended correctly tells us when a course is over.""" """Check that has_ended correctly tells us when a course is over."""
self.assertTrue(self.past_show_certs.has_ended()) self.assertTrue(self.past_show_certs.has_ended())
self.assertTrue(self.past_show_certs_no_info.has_ended())
self.assertTrue(self.past_noshow_certs.has_ended()) self.assertTrue(self.past_noshow_certs.has_ended())
self.assertFalse(self.future_show_certs.has_ended()) self.assertFalse(self.future_show_certs.has_ended())
self.assertFalse(self.future_show_certs_no_info.has_ended())
self.assertFalse(self.future_noshow_certs.has_ended()) self.assertFalse(self.future_noshow_certs.has_ended())
def test_may_certify(self): def test_may_certify(self):
"""Check that may_certify correctly tells us when a course may wrap.""" """Check that may_certify correctly tells us when a course may wrap."""
self.assertTrue(self.past_show_certs.may_certify()) self.assertTrue(self.past_show_certs.may_certify())
self.assertTrue(self.past_noshow_certs.may_certify()) self.assertTrue(self.past_noshow_certs.may_certify())
self.assertTrue(self.past_show_certs_no_info.may_certify())
self.assertTrue(self.future_show_certs.may_certify()) self.assertTrue(self.future_show_certs.may_certify())
self.assertTrue(self.future_show_certs_no_info.may_certify())
self.assertFalse(self.future_noshow_certs.may_certify()) self.assertFalse(self.future_noshow_certs.may_certify())
......
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