Commit 5557eae2 by McKenzie Welter Committed by GitHub

Merge pull request #16212 from edx/McKenzieW/cert-lookup-logic-fix

extended parameters of non-language-specific custom certificate templates
parents 092183d8 8f31c1f2
......@@ -513,12 +513,12 @@ def get_language_specific_template_or_default(language, templates):
Returns default templates If no language matches, or language passed is None
"""
two_letter_language = _get_two_letter_language_code(language)
language_or_default_templates = list(templates.filter(Q(language=two_letter_language) | Q(language=None)))
language_specific_template = get_language_specific_template(language, language_or_default_templates)
language_or_default_templates = list(templates.filter(Q(language=two_letter_language) | Q(language=None) | Q(language='')))
language_specific_template = get_language_specific_template(two_letter_language, language_or_default_templates)
if language_specific_template:
return language_specific_template
else:
return language_or_default_templates[0] if language_or_default_templates else None
return get_all_languages_or_default_template(language_or_default_templates)
def get_language_specific_template(language, templates):
......@@ -528,6 +528,13 @@ def get_language_specific_template(language, templates):
return None
def get_all_languages_or_default_template(templates):
for template in templates:
if template.language == '':
return template
return templates[0] if templates else None
def _get_two_letter_language_code(language_code):
"""
Shortens language to only first two characters (e.g. es-419 becomes es)
......
......@@ -1074,6 +1074,13 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_null_lang_template')
#create an org_mode_and_coursekey template language=''
self._create_custom_named_template('test_all_languages_template', org_id=1, mode='honor', course_key=unicode(self.course.id), language='')
#verify returns null lang template
response = self.client.get(test_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_all_languages_template')
#create a org_mode_and_coursekey template language=lang
self._create_custom_named_template('test_right_lang_template', org_id=1, mode='honor', course_key=unicode(self.course.id), language=right_language)
# verify return right_language template
......@@ -1119,6 +1126,13 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_null_lang_template')
#create an org and mode template language=''
self._create_custom_named_template('test_all_languages_template', org_id=1, mode='honor', language='')
#verify returns All Languages template
response = self.client.get(test_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_all_languages_template')
#create a org and mode template language=lang
self._create_custom_named_template('test_right_lang_template', org_id=1, mode='honor', language=right_language)
# verify return right_language template
......@@ -1162,6 +1176,13 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_null_lang_template')
#create an org template language=''
self._create_custom_named_template('test_all_languages_template', org_id=1, language='')
#verify returns All Languages template
response = self.client.get(test_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_all_languages_template')
#create a org template language=lang
self._create_custom_named_template('test_right_lang_template', org_id=1, language=right_language)
# verify return right_language template
......@@ -1206,6 +1227,13 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_null_lang_template')
#create a mode template language=''
self._create_custom_named_template('test_all_languages_template', mode='honor', language='')
#verify returns All Languages template
response = self.client.get(test_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_all_languages_template')
#create a mode template language=lang
self._create_custom_named_template('test_right_lang_template', mode='honor', language=right_language)
# verify return right_language template
......@@ -1249,6 +1277,13 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_null_lang_template')
#create a mode template language=''
self._create_custom_named_template('test_all_languages_template', org_id=1, mode='honor', language='')
#verify returns All Languages template
response = self.client.get(test_url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'course name: test_all_languages_template')
#create a mode template language=lang
self._create_custom_named_template('test_right_lang_template', org_id=1, mode='honor', language=right_language)
# verify return right_language template
......
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