def _update_course_context(request, context, course, course_key, platform_name): """ Updates context dictionary with course info. """ context['full_course_image_url'] = request.build_absolute_uri(course_image_url(course)) course_title_from_cert = context['certificate_data'].get('course_title', '') accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name context['accomplishment_copy_course_name'] = accomplishment_copy_course_name course_number = course.display_coursenumber if course.display_coursenumber else course.number context['course_number'] = course_number if context['organization_long_name']: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _('a course of study offered by {partner_short_name}, ' 'an online learning initiative of ' '{partner_long_name}.').format( partner_short_name=context['organization_short_name'], partner_long_name=context['organization_long_name'], platform_name=platform_name) else: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _('a course of study offered by ' '{partner_short_name}.').format( partner_short_name=context['organization_short_name'], platform_name=platform_name) # If language specific templates are enabled for the course, add course_run specific information to the context if CertificateGenerationCourseSetting.is_language_specific_templates_enabled_for_course(course_key): fields = ['start', 'end', 'max_effort', 'language'] course_run_data = get_course_run_details(course_key, fields) context.update(course_run_data)
def _update_course_context(request, context, course, course_key, platform_name): """ Updates context dictionary with course info. """ context['full_course_image_url'] = request.build_absolute_uri( course_image_url(course)) course_title_from_cert = context['certificate_data'].get( 'course_title', '') accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name context[ 'accomplishment_copy_course_name'] = accomplishment_copy_course_name course_number = course.display_coursenumber if course.display_coursenumber else course.number context['course_number'] = course_number if context['organization_long_name']: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _( 'a course of study offered by {partner_short_name}, ' 'an online learning initiative of ' '{partner_long_name}.').format( partner_short_name=context['organization_short_name'], partner_long_name=context['organization_long_name'], platform_name=platform_name) else: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _( 'a course of study offered by ' '{partner_short_name}.').format( partner_short_name=context['organization_short_name'], platform_name=platform_name) # If language specific templates are enabled for the course, add course_run specific information to the context if CertificateGenerationCourseSetting.is_language_specific_templates_enabled_for_course( course_key): fields = ['start', 'end', 'max_effort', 'content_language'] course_run_data = get_course_run_details(course_key, fields) if course_run_data['start'] and course_run_data[ 'end'] and course_run_data['max_effort']: # Calculate duration of the course run in weeks, multiplied by max_effort for total Hours of Effort try: start = parser.parse(course_run_data['start']) end = parser.parse(course_run_data['end']) max_effort = int(course_run_data['max_effort']) context['hours_of_effort'] = ( (end - start).days / 7) * max_effort except ValueError: log.exception( 'Error occurred while parsing course run details') context['content_language'] = course_run_data['content_language']
def _update_course_context(request, context, course, course_key, platform_name): """ Updates context dictionary with course info. """ context['full_course_image_url'] = request.build_absolute_uri( course_image_url(course)) course_title_from_cert = context['certificate_data'].get( 'course_title', '') accomplishment_copy_course_name = course_title_from_cert if course_title_from_cert else course.display_name context[ 'accomplishment_copy_course_name'] = accomplishment_copy_course_name course_number = course.display_coursenumber if course.display_coursenumber else course.number context['course_number'] = course_number if context['organization_long_name']: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _( 'a course of study offered by {partner_short_name}, ' 'an online learning initiative of ' '{partner_long_name}.').format( partner_short_name=context['organization_short_name'], partner_long_name=context['organization_long_name'], platform_name=platform_name) else: # Translators: This text represents the description of course context['accomplishment_copy_course_description'] = _( 'a course of study offered by ' '{partner_short_name}.').format( partner_short_name=context['organization_short_name'], platform_name=platform_name) # If language specific templates are enabled for the course, add course_run specific information to the context if CertificateGenerationCourseSetting.is_language_specific_templates_enabled_for_course( course_key): fields = ['start', 'end', 'max_effort', 'language'] course_run_data = get_course_run_details(course_key, fields) context.update(course_run_data)