Beispiel #1
0
def content_recommender(request):
    """Populate response with recommendation(s)"""

    user_id = request.GET.get('user')
    user = request.session.get('facility_user')

    if not user:
        if request.user.is_authenticated() and request.user.is_superuser:
            user = get_object_or_404(FacilityUser, pk=user_id)
        else:
            return JsonResponseMessageError("You are not authorized to view these recommendations.", status=401)

    resume = request.GET.get('resume')
    next = request.GET.get('next')
    explore = request.GET.get('explore')

    def set_bool_flag(flag_name, rec_dict):
        rec_dict[flag_name] = True
        return rec_dict

    # retrieve resume recommendation(s) and set resume boolean flag
    resume_recommendations = [set_bool_flag("resume", rec) for rec in get_resume_recommendations(user, request)] if resume else []

    # retrieve next_steps recommendations, set next_steps boolean flag, and flatten results for api response
    next_recommendations = [set_bool_flag("next", rec) for rec in get_next_recommendations(user, request)] if next else []

    # retrieve explore recommendations, set explore boolean flag, and flatten results for api response
    explore_recommendations = [set_bool_flag("explore", rec) for rec in get_explore_recommendations(user, request)] if explore else []

    return JsonResponse(resume_recommendations + next_recommendations + explore_recommendations)
Beispiel #2
0
    def test_get_empty_list_invalid_resume(self):
        # Used to mock a request object that is only queried for its 'lang' property.
        class MicroMock(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        # test user with invalid activity
        actual = get_resume_recommendations(self.user_with_old_activity, MicroMock(language="en"))

        # ensure that no recommendations are returned
        self.assertEqual(len(actual), 0)
Beispiel #3
0
    def test_get_empty_list_invalid_resume(self):
        # Used to mock a request object that is only queried for its 'lang' property.
        class MicroMock(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        # test user with invalid activity
        actual = get_resume_recommendations(self.user_with_old_activity, MicroMock(language="en"))

        # ensure that no recommendations are returned
        self.assertEqual(len(actual), 0)
Beispiel #4
0
def content_recommender(request):
    """Populate response with recommendation(s)"""

    user_id = request.GET.get('user', None)
    user = request.session.get('facility_user')

    if not user:
        if request.user.is_authenticated() and request.user.is_superuser:
            user = get_object_or_404(FacilityUser, pk=user_id)
        else:
            return JsonResponseMessageError(
                "You are not authorized to view these recommendations.",
                status=401)

    resume = request.GET.get('resume', None)
    next = request.GET.get('next', None)
    explore = request.GET.get('explore', None)

    def set_bool_flag(flag_name, rec_dict):
        rec_dict[flag_name] = True
        return rec_dict

    # retrieve resume recommendation(s) and set resume boolean flag
    resume_recommendations = [
        set_bool_flag("resume", rec)
        for rec in get_resume_recommendations(user, request)
    ] if resume else []

    # retrieve next_steps recommendations, set next_steps boolean flag, and flatten results for api response
    next_recommendations = [
        set_bool_flag("next", rec)
        for rec in get_next_recommendations(user, request)
    ] if next else []

    # retrieve explore recommendations, set explore boolean flag, and flatten results for api response
    explore_recommendations = [
        set_bool_flag("explore", rec)
        for rec in get_explore_recommendations(user, request)
    ] if explore else []

    return JsonResponse(resume_recommendations + next_recommendations +
                        explore_recommendations)