From bed7d80777a5360200e3beef9b371d54922ceaf7 Mon Sep 17 00:00:00 2001 From: Zia Fazal Date: Thu, 16 Jul 2015 10:11:56 +0500 Subject: [PATCH] enable certificate generation for html certificates Enable Student-Generated Certificates for HTML certs flow --- .../instructor/tests/test_certificates.py | 17 +++++++++++ .../instructor/views/instructor_dashboard.py | 30 +++++++++++-------- .../instructor_dashboard_2/certificates.html | 2 ++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py index 84cae88433..22d8f7267f 100644 --- a/lms/djangoapps/instructor/tests/test_certificates.py +++ b/lms/djangoapps/instructor/tests/test_certificates.py @@ -7,6 +7,7 @@ import json from nose.plugins.attrib import attr from django.core.urlresolvers import reverse from django.test.utils import override_settings +from django.conf import settings from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from config_models.models import cache @@ -94,6 +95,22 @@ class CertificatesInstructorDashTest(ModuleStoreTestCase): certs_api.set_cert_generation_enabled(self.course.id, True) self._assert_enable_certs_button(False) + @mock.patch.dict(settings.FEATURES, {'CERTIFICATES_HTML_VIEW': True}) + def test_show_enabled_button_for_html_certs(self): + """ + Tests `Enable Student-Generated Certificates` button is enabled + and `Generate Example Certificates` button is not available if + course has Web/HTML certificates view enabled. + """ + self.course.cert_html_view_enabled = True + self.course.save() + self.store.update_item(self.course, self.global_staff.id) # pylint: disable=no-member + self.client.login(username=self.global_staff.username, password="test") + response = self.client.get(self.url) + self.assertContains(response, 'Enable Student-Generated Certificates') + self.assertContains(response, 'enable-certificates-submit') + self.assertNotContains(response, 'Generate Example Certificates') + def _assert_certificates_visible(self, is_visible): """Check that the certificates section is visible on the instructor dash. """ response = self.client.get(self.url) diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index d783337b9a..19f89d6350 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -231,20 +231,25 @@ def _section_certificates(course): dict """ - example_cert_status = certs_api.example_certificates_status(course.id) + example_cert_status = None + html_cert_enabled = certs_api.has_html_certificates_enabled(course.id, course) + if html_cert_enabled: + can_enable_for_course = True + else: + example_cert_status = certs_api.example_certificates_status(course.id) - # Allow the user to enable self-generated certificates for students - # *only* once a set of example certificates has been successfully generated. - # If certificates have been misconfigured for the course (for example, if - # the PDF template hasn't been uploaded yet), then we don't want - # to turn on self-generated certificates for students! - can_enable_for_course = ( - example_cert_status is not None and - all( - cert_status['status'] == 'success' - for cert_status in example_cert_status + # Allow the user to enable self-generated certificates for students + # *only* once a set of example certificates has been successfully generated. + # If certificates have been misconfigured for the course (for example, if + # the PDF template hasn't been uploaded yet), then we don't want + # to turn on self-generated certificates for students! + can_enable_for_course = ( + example_cert_status is not None and + all( + cert_status['status'] == 'success' + for cert_status in example_cert_status + ) ) - ) instructor_generation_enabled = settings.FEATURES.get('CERTIFICATES_INSTRUCTOR_GENERATION', False) return { @@ -254,6 +259,7 @@ def _section_certificates(course): 'can_enable_for_course': can_enable_for_course, 'enabled_for_course': certs_api.cert_generation_enabled(course.id), 'instructor_generation_enabled': instructor_generation_enabled, + 'html_cert_enabled': html_cert_enabled, 'urls': { 'generate_example_certificates': reverse( 'generate_example_certificates', diff --git a/lms/templates/instructor/instructor_dashboard_2/certificates.html b/lms/templates/instructor/instructor_dashboard_2/certificates.html index 9180a304d6..d67d3fe04b 100644 --- a/lms/templates/instructor/instructor_dashboard_2/certificates.html +++ b/lms/templates/instructor/instructor_dashboard_2/certificates.html @@ -3,6 +3,7 @@
+ % if not section_data['html_cert_enabled']:

${_('Example Certificates')}

@@ -13,6 +14,7 @@
+ % endif % if section_data['example_certificate_status'] is not None: