Commit 8baf5868 by Waheed Ahmed

Merge pull request #12210 from edx/waheed/ecom-3437-enable-self-gen-certs-by-default-for-self-paced

Automatically enable Self Generating Certificates for Self Paced Courses.
parents f7ec039b f246c6bb
""" Certificates app """
# this is here to support registering the signals in signals.py
from . import signals
""" Signal handler for enabling self-generated certificates by default
for self-paced courses.
"""
from celery.task import task
from django.dispatch.dispatcher import receiver
from certificates.models import CertificateGenerationCourseSetting
from xmodule.modulestore.django import SignalHandler, modulestore
@receiver(SignalHandler.course_published)
def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument
""" Catches the signal that a course has been published in Studio and
enable the self-generated certificates by default for self-paced
courses.
"""
enable_self_generated_certs.delay(course_key)
@task()
def enable_self_generated_certs(course_key):
"""Enable the self-generated certificates by default for self-paced courses."""
course = modulestore().get_course(course_key)
is_enabled_for_course = CertificateGenerationCourseSetting.is_enabled_for_course(course_key)
if course.self_paced and not is_enabled_for_course:
CertificateGenerationCourseSetting.set_enabled_for_course(course_key, True)
""" Unit tests for enabling self-generated certificates by default
for self-paced courses.
"""
from certificates import api as certs_api
from certificates.models import CertificateGenerationConfiguration
from certificates.signals import _listen_for_course_publish
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
""" Tests for enabling self-generated certificates by default
for self-paced courses.
"""
def setUp(self):
super(SelfGeneratedCertsSignalTest, self).setUp()
SelfPacedConfiguration(enabled=True).save()
self.course = CourseFactory.create(self_paced=True)
# Enable the feature
CertificateGenerationConfiguration.objects.create(enabled=True)
def test_cert_generation_enabled_for_self_paced(self):
""" Verify the signal enable the self-generated certificates by default for
self-paced courses.
"""
self.assertFalse(certs_api.cert_generation_enabled(self.course.id))
_listen_for_course_publish('store', self.course.id)
self.assertTrue(certs_api.cert_generation_enabled(self.course.id))
...@@ -327,6 +327,7 @@ def _section_certificates(course): ...@@ -327,6 +327,7 @@ def _section_certificates(course):
'example_certificate_status': example_cert_status, 'example_certificate_status': example_cert_status,
'can_enable_for_course': can_enable_for_course, 'can_enable_for_course': can_enable_for_course,
'enabled_for_course': certs_api.cert_generation_enabled(course.id), 'enabled_for_course': certs_api.cert_generation_enabled(course.id),
'is_self_paced': course.self_paced,
'instructor_generation_enabled': instructor_generation_enabled, 'instructor_generation_enabled': instructor_generation_enabled,
'html_cert_enabled': html_cert_enabled, 'html_cert_enabled': html_cert_enabled,
'active_certificate': certs_api.get_active_web_certificate(course), 'active_certificate': certs_api.get_active_web_certificate(course),
......
...@@ -50,27 +50,29 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str ...@@ -50,27 +50,29 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
% endif % endif
</div> </div>
<hr /> % if not section_data['is_self_paced']:
<hr />
<div class="enable-certificates">
<h2>${_("Student-Generated Certificates")}</h2> <div class="enable-certificates">
% if section_data['enabled_for_course']: <h2>${_("Student-Generated Certificates")}</h2>
<form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}"> % if section_data['enabled_for_course']:
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"> <form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}">
<input type="hidden" id="certificates-enabled" name="certificates-enabled" value="false" /> <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
<input type="submit" class="btn-blue" id="disable-certificates-submit" value="${_('Disable Student-Generated Certificates')}"/> <input type="hidden" id="certificates-enabled" name="certificates-enabled" value="false" />
</form> <input type="submit" class="btn-blue" id="disable-certificates-submit" value="${_('Disable Student-Generated Certificates')}"/>
% elif section_data['can_enable_for_course']: </form>
<form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}"> % elif section_data['can_enable_for_course']:
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"> <form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}">
<input type="hidden" id="certificates-enabled" name="certificates-enabled" value="true" /> <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
<input type="submit" class="btn-blue" id="enable-certificates-submit" value="${_('Enable Student-Generated Certificates')}"/> <input type="hidden" id="certificates-enabled" name="certificates-enabled" value="true" />
</form> <input type="submit" class="btn-blue" id="enable-certificates-submit" value="${_('Enable Student-Generated Certificates')}"/>
% else: </form>
<p>${_("You must successfully generate example certificates before you enable student-generated certificates.")}</p> % else:
<button class="is-disabled" disabled>${_('Enable Student-Generated Certificates')}</button> <p>${_("You must successfully generate example certificates before you enable student-generated certificates.")}</p>
% endif <button class="is-disabled" disabled>${_('Enable Student-Generated Certificates')}</button>
</div> % endif
</div>
% endif
% if section_data['instructor_generation_enabled'] and not (section_data['enabled_for_course'] and section_data['html_cert_enabled']): % if section_data['instructor_generation_enabled'] and not (section_data['enabled_for_course'] and section_data['html_cert_enabled']):
<hr class="section-divider" /> <hr class="section-divider" />
......
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