From b8d73df5a464c54f1250ae81c540320c548d4d71 Mon Sep 17 00:00:00 2001 From: Sofiya Semenova Date: Fri, 6 Oct 2017 16:15:38 -0400 Subject: [PATCH] Cleaning up dashboard_certificate_information template. --- common/djangoapps/student/tests/test_views.py | 5 +-- common/djangoapps/student/tests/tests.py | 45 +++++++------------ common/djangoapps/student/views.py | 37 +++++++-------- .../_dashboard_certificate_information.html | 42 +++++++++-------- 4 files changed, 57 insertions(+), 72 deletions(-) diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 18b2cd38b2..cf20f209f9 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -57,10 +57,9 @@ class TestStudentDashboardUnenrollments(SharedModuleStoreTestCase): return { 'status': self.cert_status, 'can_unenroll': self.cert_status not in DISABLE_UNENROLL_CERT_STATES, - 'certificate_message_viewable': True, + 'download_url': 'fake_url', + 'linked_in_url': False, 'grade': 100, - 'show_disabled_download_button': False, - 'show_download_url': False, 'show_survey_button': False } diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index f22180c8ea..00313a0356 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -83,9 +83,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, None, course_mode), { 'status': 'processing', - 'show_disabled_download_button': False, - 'certificate_message_viewable': False, - 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, } @@ -96,9 +93,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', - 'show_disabled_download_button': False, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': False, 'mode': None, 'linked_in_url': None, @@ -113,9 +107,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', - 'show_disabled_download_button': True, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '1.0', @@ -130,9 +121,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', - 'show_disabled_download_button': True, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '0.67', @@ -154,9 +142,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'downloadable', - 'show_disabled_download_button': False, - 'certificate_message_viewable': True, - 'show_download_url': True, 'download_url': download_url, 'show_survey_button': True, 'survey_url': survey_url, @@ -176,9 +161,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'notpassing', - 'show_disabled_download_button': False, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': '0.67', @@ -198,9 +180,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course2, cert_status, course_mode), { 'status': 'notpassing', - 'show_disabled_download_button': False, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': False, 'grade': '0.67', 'mode': 'honor', @@ -212,14 +191,28 @@ class CourseEndingTest(TestCase): # test when the display is unavailable or notpassing, we get the correct results out course2.certificates_display_behavior = 'early_no_info' cert_status = {'status': 'unavailable'} - self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {}) + self.assertEqual( + _cert_info(user, course2, cert_status, course_mode), + { + 'status': 'processing', + 'show_survey_button': False, + 'can_unenroll': True, + } + ) cert_status = { 'status': 'notpassing', 'grade': '0.67', 'download_url': download_url, 'mode': 'honor' } - self.assertEqual(_cert_info(user, course2, cert_status, course_mode), {}) + self.assertEqual( + _cert_info(user, course2, cert_status, course_mode), + { + 'status': 'processing', + 'show_survey_button': False, + 'can_unenroll': True, + } + ) @ddt.data( (0.70, 0.60), @@ -258,9 +251,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'generating', - 'show_disabled_download_button': True, - 'certificate_message_viewable': True, - 'show_download_url': False, 'show_survey_button': True, 'survey_url': survey_url, 'grade': unicode(expected_grade), @@ -292,9 +282,6 @@ class CourseEndingTest(TestCase): _cert_info(user, course, cert_status, course_mode), { 'status': 'processing', - 'certificate_message_viewable': False, - 'show_disabled_download_button': False, - 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, } diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 891315d238..457e0c2790 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -234,11 +234,9 @@ def cert_info(user, course_overview, course_mode): Returns: dict: A dictionary with keys: - 'status': one of 'generating', 'downloadable', 'notpassing', 'processing', 'restricted' - 'show_download_url': bool - 'certificate_message_viewable': bool -- if certificates are viewable + 'status': one of 'generating', 'downloadable', 'notpassing', 'processing', 'restricted', 'unavailable', or + 'certificate_earned_but_not_available' 'download_url': url, only present if show_download_url is True - 'show_disabled_download_button': bool -- true if state is 'generating' 'show_survey_button': bool 'survey_url': url, only if show_survey_button is True 'grade': if status is not 'processing' @@ -359,13 +357,11 @@ def _cert_info(user, course_overview, cert_status, course_mode): # pylint: disa CertificateStatuses.unverified: 'unverified', } + certificate_earned_but_not_available_status = 'certificate_earned_but_not_available' default_status = 'processing' default_info = { 'status': default_status, - 'certificate_message_viewable': False, - 'show_disabled_download_button': False, - 'show_download_url': False, 'show_survey_button': False, 'can_unenroll': True, } @@ -373,25 +369,30 @@ def _cert_info(user, course_overview, cert_status, course_mode): # pylint: disa if cert_status is None: return default_info - is_hidden_status = cert_status['status'] in ('unavailable', 'processing', 'generating', 'notpassing', 'auditing') - - if course_overview.certificates_display_behavior == 'early_no_info' and is_hidden_status: - return {} - status = template_state.get(cert_status['status'], default_status) + is_hidden_status = status in ('unavailable', 'processing', 'generating', 'notpassing', 'auditing') + + if ( + not certificates_viewable_for_course(course_overview) and + (status in CertificateStatuses.PASSED_STATUSES) and + course_overview.certificate_available_date + ): + status = certificate_earned_but_not_available_status + + if ( + course_overview.certificates_display_behavior == 'early_no_info' and + is_hidden_status + ): + return default_info status_dict = { 'status': status, - 'certificate_message_viewable': certificates_viewable_for_course(course_overview), - 'show_download_url': status == 'downloadable', - 'show_disabled_download_button': status == 'generating', 'mode': cert_status.get('mode', None), 'linked_in_url': None, 'can_unenroll': status not in DISABLE_UNENROLL_CERT_STATES, } - if (status in ('generating', 'downloadable', 'notpassing', 'restricted', 'auditing', 'unverified') and - course_overview.end_of_course_survey_url is not None): + if not status == default_status and course_overview.end_of_course_survey_url is not None: status_dict.update({ 'show_survey_button': True, 'survey_url': process_survey_link(course_overview.end_of_course_survey_url, user)}) @@ -408,7 +409,7 @@ def _cert_info(user, course_overview, cert_status, course_mode): # pylint: disa }) else: # don't show download certificate button if we don't have an active certificate for course - status_dict['show_download_url'] = False + status_dict['status'] = 'unavailable' elif 'download_url' not in cert_status: log.warning( u"User %s has a downloadable cert for %s, but no download url", diff --git a/lms/templates/dashboard/_dashboard_certificate_information.html b/lms/templates/dashboard/_dashboard_certificate_information.html index f9c8951430..99820d8f33 100644 --- a/lms/templates/dashboard/_dashboard_certificate_information.html +++ b/lms/templates/dashboard/_dashboard_certificate_information.html @@ -18,7 +18,7 @@ from course_modes.models import CourseMode %> <% -if (cert_status['status'] == 'generating' or cert_status['status'] == 'downloadable') and not cert_status['certificate_message_viewable']: +if cert_status['status'] == 'certificate_earned_but_not_available': status_css_class = 'course-status-processing' elif cert_status['status'] == 'generating': status_css_class = 'course-status-certrendering' @@ -31,19 +31,17 @@ else: %> % if cert_status['status'] != 'processing': - % if not cert_status['certificate_message_viewable']: - % if (cert_status['status'] == 'generating' or cert_status['status'] == 'downloadable') and course_overview.certificate_available_date: -
-

- <% - certificate_available_date_string = course_overview.certificate_available_date.strftime('%Y-%m-%dT%H:%M:%S%z') - container_string = _("Your certificate will be available on or before {date}") - format = 'shortDate' - %> - -

-
- % endif + % if cert_status['status'] == 'certificate_earned_but_not_available': +
+

+ <% + certificate_available_date_string = course_overview.certificate_available_date.strftime('%Y-%m-%dT%H:%M:%S%z') + container_string = _("Your certificate will be available on or before {date}") + format = 'shortDate' + %> + +

+
% else:

${_("Your final grade:")} @@ -73,37 +71,37 @@ else:

- % if cert_status['show_disabled_download_button'] or cert_status['show_download_url'] or cert_status['show_survey_button']: + % if cert_status['status'] == 'generating' or cert_status['status'] == 'downloadable' or cert_status['show_survey_button']:
- % if cert_status['show_download_url'] and cert_status['linked_in_url']: + % if cert_status['status'] == 'downloadable' and cert_status['linked_in_url']: