From 4d5a4b035d73fa3bc556046c8cee60c135f243d8 Mon Sep 17 00:00:00 2001 From: Awais Date: Thu, 11 Jun 2015 23:11:41 +0500 Subject: [PATCH] ECOM-1683 removing regen-cert code. --- lms/djangoapps/certificates/queue.py | 11 +-- lms/djangoapps/courseware/tests/test_views.py | 32 ++------ lms/djangoapps/courseware/views.py | 4 +- lms/templates/courseware/progress.html | 79 +++++++++---------- 4 files changed, 48 insertions(+), 78 deletions(-) diff --git a/lms/djangoapps/certificates/queue.py b/lms/djangoapps/certificates/queue.py index 6a527bd05c..b1ced7591b 100644 --- a/lms/djangoapps/certificates/queue.py +++ b/lms/djangoapps/certificates/queue.py @@ -262,16 +262,7 @@ class XQueueCertInterface(object): if forced_grade: grade['grade'] = forced_grade - cert, created = GeneratedCertificate.objects.get_or_create(user=student, course_id=course_id) - - if not created: - LOGGER.info( - u"Regenerate certificate for user %s in course %s " - u"with status %s, download_uuid %s, " - u"and download_url %s", - cert.user.id, unicode(cert.course_id), - cert.status, cert.download_uuid, cert.download_url - ) + cert, __ = GeneratedCertificate.objects.get_or_create(user=student, course_id=course_id) cert.mode = cert_mode cert.user = student diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 81db9764d6..5e511086af 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -1042,8 +1042,9 @@ class GenerateUserCertTests(ModuleStoreTestCase): @patch('courseware.grades.grade', Mock(return_value={'grade': 'Pass', 'percent': 0.75})) @override_settings(CERT_QUEUE='certificates', SEGMENT_IO_LMS_KEY="foobar", FEATURES={'SEGMENT_IO_LMS': True}) def test_user_with_passing_existing_downloadable_cert(self): - # If user has already downloadable certificate then he can again re-generate the - # the cert. + # If user has already downloadable certificate + # then json will return cert generating message with bad request code + GeneratedCertificateFactory.create( user=self.student, course_id=self.course.id, @@ -1051,30 +1052,9 @@ class GenerateUserCertTests(ModuleStoreTestCase): mode='verified' ) - analytics_patcher = patch('courseware.views.analytics') - mock_tracker = analytics_patcher.start() - self.addCleanup(analytics_patcher.stop) - - with patch('capa.xqueue_interface.XQueueInterface.send_to_queue') as mock_send_to_queue: - mock_send_to_queue.return_value = (0, "Successfully queued") - resp = self.client.post(self.url) - self.assertEqual(resp.status_code, 200) - - #Verify Google Analytics event fired after generating certificate - mock_tracker.track.assert_called_once_with( # pylint: disable=no-member - self.student.id, # pylint: disable=no-member - 'edx.bi.user.certificate.generate', - { - 'category': 'certificates', - 'label': unicode(self.course.id) - }, - - context={ - 'Google Analytics': - {'clientId': None} - } - ) - mock_tracker.reset_mock() + resp = self.client.post(self.url) + self.assertEqual(resp.status_code, HttpResponseBadRequest.status_code) + self.assertIn("Certificate has already been created.", resp.content) def test_user_with_non_existing_course(self): # If try to access a course with valid key pattern then it will return diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 7d0dcdb329..b82ebf005e 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -1349,7 +1349,9 @@ def generate_user_cert(request, course_id): certificate_status = certs_api.certificate_downloadable_status(student, course.id) - if certificate_status["is_generating"]: + if certificate_status["is_downloadable"]: + return HttpResponseBadRequest(_("Certificate has already been created.")) + elif certificate_status["is_generating"]: return HttpResponseBadRequest(_("Certificate is being created.")) else: # If the certificate is not already in-process or completed, diff --git a/lms/templates/courseware/progress.html b/lms/templates/courseware/progress.html index 975756d823..950dacfb21 100644 --- a/lms/templates/courseware/progress.html +++ b/lms/templates/courseware/progress.html @@ -51,53 +51,50 @@ from django.utils.http import urlquote_plus
-
-
%if passed: +
+
+ % if is_downloadable and download_url: - % if is_downloadable and download_url: - - <% 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.")}

+
+

${_("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 updated certificate.")} +

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

${_("We're working on it...")}

+

${_("We're creating your certificate. You can keep working in your courses and a link to it will appear here and on your Dashboard when it is ready.")}

+
+
%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"")} -

+
+

${_("Congratulations, you qualified for a certificate!")}

+

${_("You can keep working for a higher grade, or request your certificate now.")}

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

${_("We're working on it...")}

-

${_("We're creating your certificate. You can keep working in your courses and a link to it will appear here and on your Dashboard when it is ready.")}

-
-
- %else: -
-

${_("Congratulations, you qualified for a certificate!")}

-

${_("You can keep working for a higher grade, or request your certificate now.")}

-
-
- -
- %endif -
+
%endif -
%endif