本文整理汇总了Python中certificates.models.CertificateGenerationCourseSetting.get方法的典型用法代码示例。如果您正苦于以下问题:Python CertificateGenerationCourseSetting.get方法的具体用法?Python CertificateGenerationCourseSetting.get怎么用?Python CertificateGenerationCourseSetting.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类certificates.models.CertificateGenerationCourseSetting
的用法示例。
在下文中一共展示了CertificateGenerationCourseSetting.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_catalog_data_for_course
# 需要导入模块: from certificates.models import CertificateGenerationCourseSetting [as 别名]
# 或者: from certificates.models.CertificateGenerationCourseSetting import get [as 别名]
def _get_catalog_data_for_course(course_key):
"""
Retrieve data from the Discovery service necessary for rendering a certificate for a specific course.
"""
course_certificate_settings = CertificateGenerationCourseSetting.get(course_key)
if not course_certificate_settings:
return {}
catalog_data = {}
course_run_fields = []
if course_certificate_settings.language_specific_templates_enabled:
course_run_fields.append('content_language')
if course_certificate_settings.include_hours_of_effort:
course_run_fields.extend(['weeks_to_complete', 'max_effort'])
if course_run_fields:
course_run_data = get_course_run_details(course_key, course_run_fields)
if course_run_data.get('weeks_to_complete') and course_run_data.get('max_effort'):
try:
weeks_to_complete = int(course_run_data['weeks_to_complete'])
max_effort = int(course_run_data['max_effort'])
catalog_data['hours_of_effort'] = weeks_to_complete * max_effort
except ValueError:
log.exception('Error occurred while parsing course run details')
catalog_data['content_language'] = course_run_data.get('content_language')
return catalog_data
示例2: _update_context_with_catalog_data
# 需要导入模块: from certificates.models import CertificateGenerationCourseSetting [as 别名]
# 或者: from certificates.models.CertificateGenerationCourseSetting import get [as 别名]
def _update_context_with_catalog_data(context, course_key):
"""
Updates context dictionary with relevant course run info from Discovery.
"""
course_certificate_settings = CertificateGenerationCourseSetting.get(course_key)
if course_certificate_settings:
course_run_fields = []
if course_certificate_settings.language_specific_templates_enabled:
course_run_fields.append('content_language')
if course_certificate_settings.include_hours_of_effort:
course_run_fields.extend(['weeks_to_complete', 'max_effort'])
if course_run_fields:
course_run_data = get_course_run_details(course_key, course_run_fields)
if course_run_data.get('weeks_to_complete') and course_run_data.get('max_effort'):
try:
weeks_to_complete = int(course_run_data['weeks_to_complete'])
max_effort = int(course_run_data['max_effort'])
context['hours_of_effort'] = weeks_to_complete * max_effort
except ValueError:
log.exception('Error occurred while parsing course run details')
context['content_language'] = course_run_data.get('content_language')