ecommerce_worker/sailthru/v1/tasks.py
def _get_course_content(course_id, course_url, sailthru_client, site_code, config):
    """Get course information using the Sailthru content api or from cache.

    If there is an error, just return with an empty response.

    Arguments:
        course_id (str): course key of the course
        course_url (str): LMS url for course info page.
        sailthru_client (object): SailthruClient
        site_code (str): site code
        config (dict): config options

    Returns:
        course information from Sailthru
    """
    # check cache first
    cache_key = "{}:{}".format(site_code, course_url)
    response = cache.get(cache_key)
    if not response:
        try:
            sailthru_response = sailthru_client.api_get("content", {"id": course_url})
            if not sailthru_response.is_ok():
                response = {}
            else:
                response = sailthru_response.json
                cache.set(cache_key, response, config.get('SAILTHRU_CACHE_TTL_SECONDS'))

        except SailthruClientError:
            response = {}

        if not response:
            logger.error('Could not get course data from Sailthru on enroll/purchase event. '
                         'Calling Ecommerce Course API to get course info for enrollment confirmation email')
            response = _get_course_content_from_ecommerce(course_id, site_code=site_code)
            if response:
                cache.set(cache_key, response, config.get('SAILTHRU_CACHE_TTL_SECONDS'))

    return response
def _get_course_content(course_id, course_url, sailthru_client, site_code, config):
    # check cache first
    cache_key = "{}:{}".format(site_code, course_url)
    response = cache.get(cache_key)
    if not response:
        try:
            sailthru_response = sailthru_client.api_get("content", {"id": course_url})
            if not sailthru_response.is_ok():
                response = {}
            else:
                response = sailthru_response.json
                cache.set(cache_key, response, config.get('SAILTHRU_CACHE_TTL_SECONDS'))

        except SailthruClientError:
            response = {}

        if not response:
            logger.error('Could not get course data from Sailthru on enroll/purchase event. '
                         'Calling Ecommerce Course API to get course info for enrollment confirmation email')
            response = _get_course_content_from_ecommerce(course_id, site_code=site_code)
            if response:
                cache.set(cache_key, response, config.get('SAILTHRU_CACHE_TTL_SECONDS'))

    return response
def _get_course_content ( course_id , course_url , sailthru_client , site_code , config ) : # check cache first cache_key = "{}:{}" . format ( site_code , course_url ) response = cache . get ( cache_key ) if not response : try : sailthru_response = sailthru_client . api_get ( "content" , { "id" : course_url } ) if not sailthru_response . is_ok ( ) : response = { } else : response = sailthru_response . json cache . set ( cache_key , response , config . get ( 'SAILTHRU_CACHE_TTL_SECONDS' ) ) except SailthruClientError : response = { } if not response : logger . error ( 'Could not get course data from Sailthru on enroll/purchase event. ' 'Calling Ecommerce Course API to get course info for enrollment confirmation email' ) response = _get_course_content_from_ecommerce ( course_id , site_code = site_code ) if response : cache . set ( cache_key , response , config . get ( 'SAILTHRU_CACHE_TTL_SECONDS' ) ) return response
Get course information using the Sailthru content api or from cache.

    If there is an error, just return with an empty response.

    Arguments:
        course_id (str): course key of the course
        course_url (str): LMS url for course info page.
        sailthru_client (object): SailthruClient
        site_code (str): site code
        config (dict): config options

    Returns:
        course information from Sailthru
Get course information using the Sailthru content api or from cache .