Beispiel #1
0
def get_certificate_template(course_key, mode, language):
    """
    Retrieves the custom certificate template based on course_key, mode, and language.
    """
    template = None
    # fetch organization of the course
    org_id = get_course_organization_id(course_key)

    # only consider active templates
    active_templates = CertificateTemplate.objects.filter(is_active=True)

    if org_id and mode:  # get template by org, mode, and key
        org_mode_and_key_templates = active_templates.filter(
            organization_id=org_id, mode=mode, course_key=course_key)
        template = get_language_specific_template_or_default(
            language, org_mode_and_key_templates, course_key)
        if template:
            log.info(
                u"Template retrieved for course based on the course_key:{course_key}, mode:{mode} "
                u"and org_id:{org_id}".format(course_key=course_key,
                                              mode=mode,
                                              org_id=org_id))

    # since no template matched that course_key, only consider templates with empty course_key
    empty_course_key_templates = active_templates.filter(
        course_key=CourseKeyField.Empty)
    if not template and org_id and mode:  # get template by org and mode
        org_and_mode_templates = empty_course_key_templates.filter(
            organization_id=org_id, mode=mode)
        template = get_language_specific_template_or_default(
            language, org_and_mode_templates, course_key)
        if template:
            log.info(
                u"Template retrieved for course:{course_key} based on the mode:{mode} "
                u"and org_id:{org_id}".format(course_key=course_key,
                                              mode=mode,
                                              org_id=org_id))
    if not template and org_id:  # get template by only org
        org_templates = empty_course_key_templates.filter(
            organization_id=org_id, mode=None)
        template = get_language_specific_template_or_default(
            language, org_templates, course_key)
        if template:
            log.info(
                u"Template retrieved for course:{course_key} and org_id:{org_id}"
                .format(course_key=course_key, org_id=org_id))
    if not template and mode:  # get template by only mode
        mode_templates = empty_course_key_templates.filter(
            organization_id=None, mode=mode)
        template = get_language_specific_template_or_default(
            language, mode_templates, course_key)
        if template:
            log.info(
                u"Template retrieved for course:{course_key} based on the mode:{mode} "
                u"and org_id:{org_id}".format(course_key=course_key,
                                              mode=mode,
                                              org_id=org_id))
    return template if template else None
Beispiel #2
0
def get_certificate_template(course_key, mode, language):
    """
    Retrieves the custom certificate template based on course_key, mode, and language.
    """
    template = None
    # fetch organization of the course
    org_id = get_course_organization_id(course_key)

    # only consider active templates
    active_templates = CertificateTemplate.objects.filter(is_active=True)

    if org_id and mode:  # get template by org, mode, and key
        org_mode_and_key_templates = active_templates.filter(
            organization_id=org_id,
            mode=mode,
            course_key=course_key
        )
        template = get_language_specific_template_or_default(language, org_mode_and_key_templates)

    # since no template matched that course_key, only consider templates with empty course_key
    empty_course_key_templates = active_templates.filter(course_key=CourseKeyField.Empty)
    if not template and org_id and mode:  # get template by org and mode
        org_and_mode_templates = empty_course_key_templates.filter(
            organization_id=org_id,
            mode=mode
        )
        template = get_language_specific_template_or_default(language, org_and_mode_templates)
    if not template and org_id:  # get template by only org
        org_templates = empty_course_key_templates.filter(
            organization_id=org_id,
            mode=None
        )
        template = get_language_specific_template_or_default(language, org_templates)
    if not template and mode:  # get template by only mode
        mode_templates = empty_course_key_templates.filter(
            organization_id=None,
            mode=mode
        )
        template = get_language_specific_template_or_default(language, mode_templates)
    return template if template else None