本文整理匯總了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')