From 288ae948577aa866cbdc568120fcd4cd79fc570e Mon Sep 17 00:00:00 2001 From: McKenzie Welter Date: Tue, 5 Sep 2017 11:25:59 -0400 Subject: [PATCH] Added language field to certificate template --- lms/djangoapps/certificates/admin.py | 9 +++++++++ .../0010_certificatetemplate_language.py | 19 +++++++++++++++++++ lms/djangoapps/certificates/models.py | 6 ++++++ lms/envs/aws.py | 1 + lms/envs/common.py | 3 +++ 5 files changed, 38 insertions(+) create mode 100644 lms/djangoapps/certificates/migrations/0010_certificatetemplate_language.py diff --git a/lms/djangoapps/certificates/admin.py b/lms/djangoapps/certificates/admin.py index afccb1fcf3..378bf4c106 100644 --- a/lms/djangoapps/certificates/admin.py +++ b/lms/djangoapps/certificates/admin.py @@ -1,8 +1,11 @@ """ django admin pages for certificates models """ +from operator import itemgetter + from config_models.admin import ConfigurationModelAdmin from django import forms +from django.conf import settings from django.contrib import admin from certificates.models import ( @@ -28,6 +31,12 @@ class CertificateTemplateForm(forms.ModelForm): self.fields['organization_id'] = forms.TypedChoiceField( choices=org_choices, required=False, coerce=int, empty_value=None ) + languages = settings.CERTIFICATE_TEMPLATE_LANGUAGES.items() + lang_choices = sorted(languages, key=itemgetter(1)) + lang_choices.insert(0, (None, 'All Languages')) + self.fields['language'] = forms.ChoiceField( + choices=lang_choices, required=False + ) class Meta(object): model = CertificateTemplate diff --git a/lms/djangoapps/certificates/migrations/0010_certificatetemplate_language.py b/lms/djangoapps/certificates/migrations/0010_certificatetemplate_language.py new file mode 100644 index 0000000000..a49d44ab99 --- /dev/null +++ b/lms/djangoapps/certificates/migrations/0010_certificatetemplate_language.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('certificates', '0009_certificategenerationcoursesetting_language_self_generation'), + ] + + operations = [ + migrations.AddField( + model_name='certificatetemplate', + name='language', + field=models.CharField(help_text='Only certificates for courses in the selected language will be rendered using this template. Course language is determined by the first two letters of the language code.', max_length=2, null=True, blank=True), + ), + ] diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index f043957cb2..f356338d51 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -1050,6 +1050,12 @@ class CertificateTemplate(TimeStampedModel): help_text=_(u'On/Off switch.'), default=False, ) + language = models.CharField( + max_length=2, + blank=True, + null=True, + help_text=u'Only certificates for courses in the selected language will be rendered using this template. Course language is determined by the first two letters of the language code.' + ) def __unicode__(self): return u'%s' % (self.name, ) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 225d78add2..bd5e4656c0 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -329,6 +329,7 @@ TIME_ZONE = ENV_TOKENS.get('TIME_ZONE', TIME_ZONE) # Translation overrides LANGUAGES = ENV_TOKENS.get('LANGUAGES', LANGUAGES) +CERTIFICATE_TEMPLATE_LANGUAGES = ENV_TOKENS.get('CERTIFICATE_TEMPLATE_LANGUAGES', CERTIFICATE_TEMPLATE_LANGUAGES) LANGUAGE_DICT = dict(LANGUAGES) LANGUAGE_CODE = ENV_TOKENS.get('LANGUAGE_CODE', LANGUAGE_CODE) LANGUAGE_COOKIE = ENV_TOKENS.get('LANGUAGE_COOKIE', LANGUAGE_COOKIE) diff --git a/lms/envs/common.py b/lms/envs/common.py index 37e2244aad..beb140bea5 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -996,6 +996,9 @@ LANGUAGES = ( LANGUAGE_DICT = dict(LANGUAGES) +# Languages supported for custom course certificate templates +CERTIFICATE_TEMPLATE_LANGUAGES = {} + USE_I18N = True USE_L10N = True