From 6f0606a00b837b184bd3a9955fa49b22136fddfe Mon Sep 17 00:00:00 2001 From: asadiqbal Date: Fri, 5 Jun 2015 18:29:17 +0500 Subject: [PATCH] asadiqbal08/SOL-961: Student-generated certificate flow shows "download" certificate button --- lms/djangoapps/courseware/tests/test_views.py | 79 +++++++++++++++++++ lms/djangoapps/courseware/views.py | 15 ++++ lms/templates/courseware/progress.html | 10 +++ 3 files changed, 104 insertions(+) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 128ab35e65..81db9764d6 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -816,6 +816,85 @@ class ProgressPageTests(ModuleStoreTestCase): resp = views.progress(self.request, course_id=unicode(self.course.id)) self.assertNotContains(resp, 'Request Certificate') + @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': True}) + @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], + 'grade_breakdown': []})) + def test_view_certificate_link(self): + """ + If certificate web view is enabled then certificate web view button should appear for user who certificate is + available/generated + """ + GeneratedCertificateFactory.create( + user=self.user, + course_id=self.course.id, + status=CertificateStatuses.downloadable, + download_url="http://www.example.com/certificate.pdf", + mode='honor' + ) + + # Enable the feature, but do not enable it for this course + CertificateGenerationConfiguration(enabled=True).save() + + # Enable certificate generation for this course + certs_api.set_cert_generation_enabled(self.course.id, True) + + #course certificate configurations + certificates = [ + { + 'id': 1, + 'name': 'Name 1', + 'description': 'Description 1', + 'course_title': 'course_title_1', + 'org_logo_path': '/t4x/orgX/testX/asset/org-logo-1.png', + 'signatories': [], + 'version': 1, + 'is_active': True + } + ] + + self.course.certificates = {'certificates': certificates} + self.course.save() + self.store.update_item(self.course, self.user.id) + + resp = views.progress(self.request, course_id=unicode(self.course.id)) + self.assertContains(resp, u"View Certificate") + self.assertContains(resp, u"You can now view your certificate") + self.assertContains(resp, certs_api.get_certificate_url(user_id=self.user.id, course_id=self.course.id)) + + # when course certificate is not active + certificates[0]['is_active'] = False + self.store.update_item(self.course, self.user.id) + + resp = views.progress(self.request, course_id=unicode(self.course.id)) + self.assertNotContains(resp, u"View Your Certificate") + self.assertNotContains(resp, u"You can now view your certificate") + self.assertContains(resp, u"We're creating your certificate.") + + @patch.dict('django.conf.settings.FEATURES', {'CERTIFICATES_HTML_VIEW': False}) + @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75, 'section_breakdown': [], + 'grade_breakdown': []})) + def test_view_certificate_link_hidden(self): + """ + If certificate web view is disabled then certificate web view button should not appear for user who certificate + is available/generated + """ + GeneratedCertificateFactory.create( + user=self.user, + course_id=self.course.id, + status=CertificateStatuses.downloadable, + download_url="http://www.example.com/certificate.pdf", + mode='honor' + ) + + # Enable the feature, but do not enable it for this course + CertificateGenerationConfiguration(enabled=True).save() + + # Enable certificate generation for this course + certs_api.set_cert_generation_enabled(self.course.id, True) + + resp = views.progress(self.request, course_id=unicode(self.course.id)) + self.assertContains(resp, u"Download Your Certificate") + @attr('shard_1') class VerifyCourseKeyDecoratorTests(TestCase): diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 7e996a4129..ea86541566 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -1063,6 +1063,21 @@ def _progress(request, course_key, student_id): if show_generate_cert_btn: context.update(certs_api.certificate_downloadable_status(student, course_key)) + # showing the certificate web view button if feature flags are enabled. + if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False): + if certs_api.get_active_web_certificate(course) is not None: + context.update({ + 'show_cert_web_view': True, + 'cert_web_view_url': u'{url}'.format( + url=certs_api.get_certificate_url(user_id=student.id, course_id=unicode(course.id)) + ) + }) + else: + context.update({ + 'is_downloadable': False, + 'is_generating': True, + 'download_url': None + }) with grades.manual_transaction(): response = render_to_response('courseware/progress.html', context) diff --git a/lms/templates/courseware/progress.html b/lms/templates/courseware/progress.html index 2c01db80a8..019c0aa399 100644 --- a/lms/templates/courseware/progress.html +++ b/lms/templates/courseware/progress.html @@ -59,15 +59,25 @@ from django.utils.http import urlquote_plus <% post_url = reverse('generate_user_cert', args=[unicode(course.id)]) %>

${_("Your certificate is available")}

+ %if show_cert_web_view: +

${_("You can now view your certificate.")}

+ %else:

${_( "You can now download your certificate as a PDF. If you keep working and receive a higher grade,you can request an {link_start} updated certificate {link_end}.").format( link_start=u"".format(post_url) ,link_end=u"")}

+ %endif
+ %if show_cert_web_view: + + ${_("View Certificate")} + + %else: ${_("Download Your Certificate")} + %endif
%elif is_generating: