示例#1
0
def tests(request):
    """
    Receives either GET or POST user and campaign ids.
    :param request: HTTP
    :return: renders tests.
    """

    campaign = common.get_campaign_from_request(request)
    user = common.get_user_from_request(request)
    candidate = common.get_candidate(user, campaign)

    tests = translate_tests(test_module.get_missing_tests(candidate, campaign),
                            request.LANGUAGE_CODE)

    end_point_params = {'campaign_id': campaign.id, 'tests': tests}

    if not candidate:
        return redirect('/servicio-de-empleo?campaign_id={}'.format(
            campaign.id))
    if user is not None:
        end_point_params['user_id'] = int(
            user.id
        )  # Adds the user id to the params, to be able to track answers, later

    if tests:
        return render(request, cts.TESTS_VIEW_PATH, end_point_params)
    else:
        return redirect(
            '/servicio-de-empleo/additional_info?candidate_id={candidate_id}'.
            format(candidate_id=candidate.pk))
示例#2
0
def update_basic_properties(request):
    """
    Args:
        request: HTTP.
    Returns: Updates just the basics of a campaign.
    """
    campaign = common.get_campaign_from_request(request)
    business_user = common.get_business_user_with_campaign(campaign)

    send_feedback_message_and_mail(business_user, campaign, request)

    campaign_module.update_campaign_basic_properties(campaign, request)
    if business_user:
        company = business_user.company
        if company:
            company.name = request.POST.get('company')
            company.save()
        else:
            company = Company()
            company.name = request.POST.get('company')
            company.save()
            business_user.company = company
            business_user.save()
    else:
        pass

    return campaign_module.get_campaign_edit_url(campaign)
示例#3
0
def update_bullets(request):
    """
    Args:
        request: HTTP.
    Returns: Updates just the basics of a campaign.
    """
    campaign = common.get_campaign_from_request(request)

    campaign_module.update_campaign_bullets(campaign, request)

    return campaign_module.get_bullets_url(campaign)
示例#4
0
def delete_interview_question(request):
    """
    Args:
        request: HTTP
    Returns: Delete question and redirects back to interviews.
    """

    campaign = common.get_campaign_from_request(request)

    interview_module.delete_question(request, campaign)

    # goes back to original page.
    return interview_module.get_redirect_url(campaign.id)
示例#5
0
def create_interview_question(request):
    """
    Given a new_token_id and texts, it creates a new question.
    Args:
        request: HTTP
    Returns: Renders the same view that it came from.
    """
    campaign = common.get_campaign_from_request(request)

    interview_module.create_question(request, campaign)

    # goes back to original page.
    return interview_module.get_redirect_url(campaign.id)
示例#6
0
def update_interview_question(request):
    """
    Updates a interview question.
    Args:
        request: HTTP
    Returns: Save info and redirects back to interviews.
    """

    campaign = common.get_campaign_from_request(request)

    interview_module.update_question(request)

    # goes back to original page.
    return interview_module.get_redirect_url(campaign.id)
示例#7
0
def delete_bullet(request):
    """
    Args:
        request: HTTP
    Returns:
    """
    bullet_id = int(request.POST.get('bullet_id'))
    bullet = Bullet.objects.get(pk=bullet_id)

    campaign = common.get_campaign_from_request(request)

    campaign.bullets.remove(bullet)
    campaign.save()

    return campaign_module.get_bullets_url(campaign)
示例#8
0
def apply(request):
    """
    When the user is logged in and applies to a second campaign
    :return:
    """

    user = User.get_user_from_request(request)
    campaign = common.get_campaign_from_request(request)

    candidate = new_user_module.candidate_if_exists(campaign, user)
    if not candidate:
        Candidate(campaign=campaign, user=user).save()

    return redirect(
        '/servicio-de-empleo/pruebas?campaign_id={campaign_id}&user_id={user_id}'
        .format(campaign_id=campaign.id, user_id=user.id))
示例#9
0
def get_test_result(request):
    """
    Args:
        request: HTTP object
    Returns: Either end process or invites to interview.
    """

    campaign = common.get_campaign_from_request(request)
    user = common.get_user_from_request(request)
    user_id = user.id if user else None
    if not user:
        return redirect('/servicio-de-empleo?campaign_id={campaign_id}'.format(
            campaign_id=campaign.id))

    candidate = common.get_candidate(user, campaign)
    high_scores = test_module.get_high_scores(candidate, campaign)

    questions_dict = test_module.get_tests_questions_dict(
        test_module.get_missing_tests(candidate,
                                      campaign,
                                      high_scores=high_scores))
    missing_scores = test_module.get_scores(campaign, user_id, questions_dict,
                                            request)

    all_scores = missing_scores + high_scores

    test_module.get_evaluation(all_scores, candidate)

    # once it has the evaluation will update the canonical user scores
    test_module.update_scores_of_candidate(candidate)

    # probably a new comer
    if candidate.user.gender is None:
        return redirect(
            '/servicio-de-empleo/additional_info?candidate_id={candidate_id}'.
            format(candidate_id=candidate.pk))
    else:
        # will no longer bother user with additional info
        if candidate is not None:
            return redirect(
                '/servicio-de-empleo/active_campaigns?candidate_id={}'.format(
                    candidate.id))
        else:
            return redirect('/servicio-de-empleo/active_campaigns')
示例#10
0
def upload_audio_file(request):
    campaign = common.get_campaign_from_request(request)
    user = common.get_user_from_request(request)
    question = Question.objects.get(pk=request.POST.get('question_id'))
    test_id = request.POST.get('test_id')

    audio_path = common.save_resource_from_request(
        request, question, 'audio', 'audio', clean_directory_on_writing=True)

    try:
        transcript = run_google_speech(audio_path)
        survey = test_module.add_survey_to_candidate(campaign, test_id,
                                                     question, user.id,
                                                     transcript)

        if audio_path != '#':
            survey.audio_path = audio_path
            survey.save()
    except Exception as e:
        print(e)
        raise e

    return HttpResponse(200)
示例#11
0
def register(request):
    """
    type=POST
    end point: peaku.co/api/v1/register

    optional params:
        email = str
        name = str
        phone = str
        work_area_id = int
        city_id = int
        google_token = str
        politics = str
        campaign_id = int

    optional FILES:
        curriculum_url
        photo_url
        brochure_url

    :param request: HTTP
    :return: 201=created, 200=updated, 400=missing google token
    """

    email = request.POST.get('email')
    name = request.POST.get('name')
    phone = request.POST.get('phone')
    work_area_id = request.POST.get('work_area_id')
    city_id = request.POST.get('city_id')
    google_token = request.POST.get('google_token')
    politics = True if request.POST.get('politics') else False

    # Only validates google token for mobile devices
    if parse(request.META['HTTP_USER_AGENT']).is_mobile and not google_token:
        return HttpResponse(400)

    campaign = common.get_campaign_from_request(request)
    country = common.get_country_with_request(request)

    user_params = {
        'country': country,
        'ip': get_ip(request),
        'is_mobile': True,
        'language_code': request.LANGUAGE_CODE
    }

    if name:
        user_params['name'] = name

    if email:
        user_params['email'] = email

    if phone:
        user_params['phone'] = phone

    if work_area_id:
        user_params['work_area_id'] = work_area_id

    if city_id:
        user_params['city'] = City.objects.get(pk=city_id)

    if politics:
        user_params['politics'] = politics

    user = new_user_module.user_if_exists(email, phone, campaign)
    if user:
        new_user_module.update_user(campaign, user, user_params, request)
        return HttpResponse(200)
    else:
        new_user_module.create_user(campaign,
                                    user_params,
                                    request,
                                    is_mobile=True)
        return HttpResponse(201)
示例#12
0
def register(request):
    """
    Args:
        request: Request object
    Returns: Saves or updates the User, now it will not be creating new user objects for the same email.
    """

    signup_form = CustomUserCreationForm(request.POST)

    if signup_form.is_valid():

        # Gets information of client: such as if it is mobile.
        is_mobile = parse(request.META['HTTP_USER_AGENT']).is_mobile

        email = request.POST.get('username')
        name = request.POST.get('name')
        phone = request.POST.get('phone')
        city_id = request.POST.get('city_id')
        work_area_id = request.POST.get('work_area_id')

        politics_accepted = request.POST.get('politics')
        if politics_accepted:
            politics = True
        else:
            politics = False
        campaign = common.get_campaign_from_request(request)

        # Validates all fields
        if campaign and name and phone and (email or not campaign.has_email):

            country = common.get_country_with_request(request)

            user_params = {
                'name': name,
                'email': email,
                'phone': phone,
                'work_area_id': work_area_id,
                'country': country,
                'city': City.objects.get(pk=city_id),
                'ip': get_ip(request),
                'is_mobile': is_mobile,
                'language_code': request.LANGUAGE_CODE,
                'politics': politics
            }

            user = new_user_module.user_if_exists(email, phone, campaign)
            if user:
                user = new_user_module.update_user(campaign,
                                                   user,
                                                   user_params,
                                                   request,
                                                   signup_form=signup_form)
            else:
                user = new_user_module.create_user(campaign,
                                                   user_params,
                                                   request,
                                                   is_mobile,
                                                   signup_form=signup_form)

            return redirect(
                '/servicio-de-empleo/pruebas?campaign_id={campaign_id}&user_id={user_id}'
                .format(campaign_id=campaign.id, user_id=user.id))
        else:
            return HttpResponseBadRequest(
                '<h1>HTTP CODE 400: Client sent bad request with missing params</h1>'
            )

    else:
        error_message = get_first_error_message(signup_form)
        params_dict = get_index_params(request)
        params_dict['error_message'] = error_message
        return render(request, cts.INDEX_VIEW_PATH, params_dict)