def get_certificate_template(course_key, mode):
 (org_id, template) = (None, None)
 course_organization = get_course_organizations(course_key)
 if course_organization:
  org_id = course_organization[0]['id']
 if (org_id and mode):
  template = CertificateTemplate.objects.filter(organization_id=org_id, course_key=course_key, mode=mode, is_active=True)
 if ((not template) and org_id and mode):
  template = CertificateTemplate.objects.filter(organization_id=org_id, course_key=CourseKeyField.Empty, mode=mode, is_active=True)
 if ((not template) and org_id):
  template = CertificateTemplate.objects.filter(organization_id=org_id, course_key=CourseKeyField.Empty, mode=None, is_active=True)
 if ((not template) and mode):
  template = CertificateTemplate.objects.filter(organization_id=None, course_key=CourseKeyField.Empty, mode=mode, is_active=True)
 return (template[0].template if template else None)

def get_certificate_template ( course_key , mode ) : ( org_id , template ) = ( None , None ) course_organization = get_course_organizations ( course_key ) if course_organization : org_id = course_organization [ 0 ] [ 'id' ] if ( org_id and mode ) : template = CertificateTemplate . objects . filter ( organization_id = org_id , course_key = course_key , mode = mode , is_active = True ) if ( ( not template ) and org_id and mode ) : template = CertificateTemplate . objects . filter ( organization_id = org_id , course_key = CourseKeyField . Empty , mode = mode , is_active = True ) if ( ( not template ) and org_id ) : template = CertificateTemplate . objects . filter ( organization_id = org_id , course_key = CourseKeyField . Empty , mode = None , is_active = True ) if ( ( not template ) and mode ) : template = CertificateTemplate . objects . filter ( organization_id = None , course_key = CourseKeyField . Empty , mode = mode , is_active = True ) return ( template [ 0 ] . template if template else None )
retrieves the custom certificate template based on course_key and mode .