Commit 2399f0ab by Michael LoTurco

Added Fields to CertificateGenerationCourseSetting

parent 14b8c12e
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"fields": { "fields": {
"modified": "2015-06-18 11:02:13.007790+00:00", "modified": "2015-06-18 11:02:13.007790+00:00",
"course_key": "course-v1:test_org+3355358979513794782079645765720179311111+test_run", "course_key": "course-v1:test_org+3355358979513794782079645765720179311111+test_run",
"enabled": true "enabled": true,
"self_generation_enabled": true
} }
}, },
{ {
......
...@@ -64,7 +64,7 @@ class CertificateGenerationCourseSettingAdmin(admin.ModelAdmin): ...@@ -64,7 +64,7 @@ class CertificateGenerationCourseSettingAdmin(admin.ModelAdmin):
""" """
Django admin customizations for CertificateGenerationCourseSetting model Django admin customizations for CertificateGenerationCourseSetting model
""" """
list_display = ('course_key', 'enabled') list_display = ('course_key', 'self_generation_enabled', 'language_specific_templates_enabled')
search_fields = ('course_key',) search_fields = ('course_key',)
show_full_result_count = False show_full_result_count = False
......
...@@ -267,7 +267,7 @@ def set_cert_generation_enabled(course_key, is_enabled): ...@@ -267,7 +267,7 @@ def set_cert_generation_enabled(course_key, is_enabled):
certificates for this course. certificates for this course.
""" """
CertificateGenerationCourseSetting.set_enabled_for_course(course_key, is_enabled) CertificateGenerationCourseSetting.set_self_generatation_enabled_for_course(course_key, is_enabled)
cert_event_type = 'enabled' if is_enabled else 'disabled' cert_event_type = 'enabled' if is_enabled else 'disabled'
event_name = '.'.join(['edx', 'certificate', 'generation', cert_event_type]) event_name = '.'.join(['edx', 'certificate', 'generation', cert_event_type])
tracker.emit(event_name, { tracker.emit(event_name, {
...@@ -321,7 +321,7 @@ def cert_generation_enabled(course_key): ...@@ -321,7 +321,7 @@ def cert_generation_enabled(course_key):
""" """
return ( return (
CertificateGenerationConfiguration.current().enabled and CertificateGenerationConfiguration.current().enabled and
CertificateGenerationCourseSetting.is_enabled_for_course(course_key) CertificateGenerationCourseSetting.is_self_generation_enabled_for_course(course_key)
) )
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import apps
from django.db import migrations, models
from django.db.models import F
def copy_field(apps, schema_editor):
CertificateGenerationCourseSetting = apps.get_model('certificates', 'CertificateGenerationCourseSetting')
CertificateGenerationCourseSetting.objects.all().update(self_generation_enabled=F('enabled'))
def undo_copy(apps, schema_editor):
CertificateGenerationCourseSetting = apps.get_model('certificates', 'CertificateGenerationCourseSetting')
CertificateGenerationCourseSetting.objects.all().update(enabled=F('self_generation_enabled'))
class Migration(migrations.Migration):
"""
Adds new field 'language_specific_templates_enabled'.
Also adds field 'self_generation_enabled' which is a
replacement for 'enabled'
Lastly, copies data from 'enabled' to 'self_generation_enabled'
"""
dependencies = [
('certificates', '0008_schema__remove_badges'),
]
operations = [
migrations.AddField(
model_name='certificategenerationcoursesetting',
name='language_specific_templates_enabled',
field=models.BooleanField(default=False, help_text="Render translated certificates rather than using the platform's default language. Available translations are controlled by the certificate template."),
),
migrations.AddField(
model_name='certificategenerationcoursesetting',
name='self_generation_enabled',
field=models.BooleanField(default=False, help_text='Allow students to generate their own certificates for the course. Enabling this does NOT affect usage of the management command used for batch certificate generation.'),
),
migrations.AlterField(
model_name='certificategenerationcoursesetting',
name='enabled',
field=models.BooleanField(default=False, help_text='DEPRECATED, please use self_generation_enabled instead.'),
),
migrations.RunPython(copy_field, reverse_code=undo_copy),
]
...@@ -842,26 +842,41 @@ class ExampleCertificate(TimeStampedModel): ...@@ -842,26 +842,41 @@ class ExampleCertificate(TimeStampedModel):
class CertificateGenerationCourseSetting(TimeStampedModel): class CertificateGenerationCourseSetting(TimeStampedModel):
"""Enable or disable certificate generation for a particular course. """Enable or disable certificate generation for a particular course.
This controls whether students are allowed to "self-generate"
certificates for a course. It does NOT prevent us from
batch-generating certificates for a course using management
commands.
In general, we should only enable self-generated certificates In general, we should only enable self-generated certificates
for a course once we successfully generate example certificates for a course once we successfully generate example certificates
for the course. This is enforced in the UI layer, but for the course. This is enforced in the UI layer, but
not in the data layer. not in the data layer.
""" """
course_key = CourseKeyField(max_length=255, db_index=True) course_key = CourseKeyField(max_length=255, db_index=True)
enabled = models.BooleanField(default=False) enabled = models.BooleanField(
default=False,
help_text=u"DEPRECATED, please use self_generation_enabled instead."
)
# TODO: Learner-2549 remove deprecated enabled field
self_generation_enabled = models.BooleanField(
default=False,
help_text=(
u"Allow students to generate their own certificates for the course. "
u"Enabling this does NOT affect usage of the management command used "
u"for batch certificate generation."
)
)
language_specific_templates_enabled = models.BooleanField(
default=False,
help_text=(
u"Render translated certificates rather than using the platform's "
u"default language. Available translations are controlled by the "
u"certificate template."
)
)
class Meta(object): class Meta(object):
get_latest_by = 'created' get_latest_by = 'created'
app_label = "certificates" app_label = "certificates"
@classmethod @classmethod
def is_enabled_for_course(cls, course_key): def is_self_generation_enabled_for_course(cls, course_key):
"""Check whether self-generated certificates are enabled for a course. """Check whether self-generated certificates are enabled for a course.
Arguments: Arguments:
...@@ -876,10 +891,10 @@ class CertificateGenerationCourseSetting(TimeStampedModel): ...@@ -876,10 +891,10 @@ class CertificateGenerationCourseSetting(TimeStampedModel):
except cls.DoesNotExist: except cls.DoesNotExist:
return False return False
else: else:
return latest.enabled return latest.self_generation_enabled
@classmethod @classmethod
def set_enabled_for_course(cls, course_key, is_enabled): def set_self_generatation_enabled_for_course(cls, course_key, is_enabled):
"""Enable or disable self-generated certificates for a course. """Enable or disable self-generated certificates for a course.
Arguments: Arguments:
...@@ -887,9 +902,46 @@ class CertificateGenerationCourseSetting(TimeStampedModel): ...@@ -887,9 +902,46 @@ class CertificateGenerationCourseSetting(TimeStampedModel):
is_enabled (boolean): Whether to enable or disable self-generated certificates. is_enabled (boolean): Whether to enable or disable self-generated certificates.
""" """
CertificateGenerationCourseSetting.objects.create( default = {
'self_generation_enabled': is_enabled
}
CertificateGenerationCourseSetting.objects.update_or_create(
course_key=course_key,
defaults=default
)
def is_language_specific_templates_enabled_for_course(cls, course_key):
"""Check whether language-specific certificates are enabled for a course.
Arguments:
course_key (CourseKey): The identifier for the course.
Returns:
boolean
"""
try:
latest = cls.objects.filter(course_key=course_key).latest()
except cls.DoesNotExist:
return False
else:
return latest.language_specific_templates_enabled
@classmethod
def set_language_specific_templates_enabled_for_course(cls, course_key, is_enabled):
"""Enable or disable language-specific certificates for a course.
Arguments:
course_key (CourseKey): The identifier for the course.
is_enabled (boolean): Whether to enable or disable language-specific certificates.
"""
default = {
'language_specific_templates_enabled': is_enabled,
}
CertificateGenerationCourseSetting.objects.update_or_create(
course_key=course_key, course_key=course_key,
enabled=is_enabled defaults=default
) )
......
...@@ -27,4 +27,4 @@ def toggle_self_generated_certs(course_key, course_self_paced): ...@@ -27,4 +27,4 @@ def toggle_self_generated_certs(course_key, course_self_paced):
""" """
Enable or disable self-generated certificates for a course according to pacing. Enable or disable self-generated certificates for a course according to pacing.
""" """
CertificateGenerationCourseSetting.set_enabled_for_course(course_key, course_self_paced) CertificateGenerationCourseSetting.set_self_generatation_enabled_for_course(course_key, course_self_paced)
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