예제 #1
0
def check_marketo_complete(course_id, email, course_map):
    """
    check if a course is already marked as complete in Marketo
    """
    # email = '*****@*****.**'
    # import pdb; pdb.set_trace()
    mkto_field_id = course_map[course_id]
    try:
        mc = get_marketo_client()
        complete = mc.execute(method='get_leads', filtr='email',
                              values=(email,), fields=(mkto_field_id,))
        if len(complete) > 1:
            raise MarketoException

        completeness = complete[0][mkto_field_id]
        if completeness:  # only cache True
            cachekey = cache_key('marketo_complete_cache',
                                 course=course_id, email=email)
            # our version of keyedcache doesn't recognize a cache is 
            # enabled in our multi-cache setup.
            if not cache_enabled():
                cache_enable()
            cache_set(cachekey, value=completeness)

        return completeness
    except MarketoException:
        # if we can't connect to Marketo or have some error with API,
        # don't continue trying to check completion
        return True
예제 #2
0
def handle_va_enrollment_event(sender, student, **kwargs):
    """
    set Marketo VA Learning Path Enrolled for Lead corresponding to user
    """
    if not (get_value("course_enable_marketo_integration", None) and not \
            getattr(settings.FEATURES, "COURSE_ENABLE_MARKETO_INTEGRATION", None)
            ):
        return

    logger.info(('Setting VA Learning Path Enrolled and edX registered for Lead with email {0}.').format(student.email))
    mkto_field_id_va = get_value("marketo_va_enrollment_field_id", None)
    mkto_field_id_edx = get_value("marketo_edx_enrollment_field_id", None)
    if not mkto_field_id_va:
        logger.warn(('Can\'t set VA Learning Path Enrolled for Lead with email {0}.').format(student.email))
    if not mkto_field_id_edx:
        logger.warn(('Can\'t set edX Registered for Lead with email {0}.').format(student.email))

    try:
        mc = get_marketo_client()
        status = mc.execute(method='update_lead', lookupField='email',
                            lookupValue=student.email,
                            values={mkto_field_id_va: True,
                                    mkto_field_id_edx: True})
        if status != 'updated':
            raise MarketoException({'message': "Update failed with status {0}".format(status), 'code': None})

    except MarketoException as e:
        logger.warn(('Can\'t set VA Learning Path Enrolled or edX Registered for Lead with email {0}.').format(student.email))
예제 #3
0
파일: views.py 프로젝트: ISCLC/edxmarketo
def test_marketo_connection(request):
    """
    Make sure we can authenticate
    """
    mc = get_marketo_client()
    try:
        mc.authenticate()
        return HttpResponse('Marketo Client authenticated successfully', status=200)
    except:
        return HttpResponse('Marketo Client could not authorize', status=400)
예제 #4
0
파일: views.py 프로젝트: ISCLC/edxmarketo
def test_marketo_connection(request):
    """
    Make sure we can authenticate
    """
    mc = get_marketo_client()
    try:
        mc.authenticate()
        return HttpResponse('Marketo Client authenticated successfully',
                            status=200)
    except:
        return HttpResponse('Marketo Client could not authorize', status=400)
예제 #5
0
파일: views.py 프로젝트: ISCLC/edxmarketo
def set_marketo_course_access_date(request):
    """
    AJAX call from course_navigation
    Set the last accessed date for this course in Marketo via REST API
    """
    errstr = ''
    email = request.user.email
    course_id = request.POST.get('course_id')
    if not email and course_id:
        return JsonResponse(
            {
                "success":
                False,
                "error":
                'Failed to update course last access date.  No course id or user',
            },
            status=500)
    try:
        mc = get_marketo_client()
        now = str(datetime.datetime.now())
        mkto_course_field_id = microsite.get_value(
            "marketo_course_access_field_map")[course_id]
        mkto_path_field_id = microsite.get_value("marketo_va_activity_field")
        status = mc.execute(method='update_lead',
                            lookupField='email',
                            lookupValue=email,
                            values={
                                mkto_course_field_id: now,
                                mkto_path_field_id: now
                            })
        if status == 'updated':
            return JsonResponse({"success": True}, status=200)

    except MarketoException as e:
        errstr = e

    logger.warn((
        'Failed to mark course {0} and Learning Path access date for Lead with '
        'email {1}.  Error: {2}').format(course_id, email, errstr))

    return JsonResponse(
        {
            "success": False,
            "error":
            'Failed to update course or learning path last access date',
        },
        status=200)
예제 #6
0
def update_marketo_complete(course_map, course_id, email, complete=True):
    """
    update Marketo course completeness field via REST API
    """
    logger.info(('Marking course {0} complete (70%+) in Marketo '
                 'for Lead with email {1}.').format(course_id, email))
    mkto_field_id = course_map[course_id]

    try:
        mc = get_marketo_client()
        status = mc.execute(method='update_lead', lookupField='email',
                            lookupValue=email,
                            values={mkto_field_id: complete})
        if status != 'updated':
            raise MarketoException({'message': "Update failed with status {0}".format(status), 'code': None})


    except MarketoException as e:
        logger.warn(('Failed to mark course {0} complete for Lead with '
                     'email {1}.  Error: {2}').format(course_id, email, e))
예제 #7
0
파일: views.py 프로젝트: ISCLC/edxmarketo
def set_marketo_course_access_date(request):
    """
    AJAX call from course_navigation
    Set the last accessed date for this course in Marketo via REST API
    """
    errstr = ''
    email = request.user.email
    course_id = request.POST.get('course_id')
    if not email and course_id:
        return JsonResponse({
            "success": False,
            "error": 'Failed to update course last access date.  No course id or user',
        }, status=500)
    try:
        mc = get_marketo_client()
        now = str(datetime.datetime.now())
        mkto_course_field_id = microsite.get_value("marketo_course_access_field_map")[course_id]
        mkto_path_field_id = microsite.get_value("marketo_va_activity_field")
        status = mc.execute(method='update_lead', lookupField='email',
                            lookupValue=email,
                            values={mkto_course_field_id: now,
                                    mkto_path_field_id: now})
        if status == 'updated':
            return JsonResponse({
                "success": True
            }, status=200)


    except MarketoException as e:
        errstr = e

    logger.warn(('Failed to mark course {0} and Learning Path access date for Lead with '
                 'email {1}.  Error: {2}').format(course_id, email, errstr))

    return JsonResponse({
        "success": False,
        "error": 'Failed to update course or learning path last access date',
    }, status=200)