Пример #1
0
    def get(self, request, employer_candidate_guid):
        template_name = "notifications/page_after_candidate_accepts.html"

        try:
            candidate = EmployerCandidate.objects.get(
                guid=employer_candidate_guid)
        except EmployerCandidate.DoesNotExist:
            return render(request, template_name, {
                "success": False,
                "no_such_guid": True
            })

        collect_contact_info_for_profile(candidate.profile)
        candidate_email = ProfileEmail.to_reach(candidate.profile.id)
        if candidate_email: candidate_email = candidate_email.value
        candidate_phone = ProfilePhoneNumber.to_reach(candidate.profile.id)
        if candidate_phone: candidate_phone = candidate_phone.value

        suggest_claim = (candidate_email is not None
                         and candidate.profile.user_id is None
                         and (request.user is None
                              or not request.user.is_authenticated))
        if suggest_claim:
            request.session['appl_accepted_email'] = candidate_email

        handle_candidate_accept(candidate)

        return render(
            request, template_name, {
                "success": True,
                "employer_candidate_guid": employer_candidate_guid,
                "candidate_email": candidate_email,
                "candidate_phone": candidate_phone,
                "suggest_claim": suggest_claim
            })
Пример #2
0
def get_recipient_email_addresses(notification, resend=False):
    """Given a Notification, return a list of email addresses as strings."""
    all_emails = []

    if notification.recipient_profile:
        collect_contact_info_for_profile(notification.recipient_profile)
        all_emails.extend(ProfileEmail.all_sane().filter(
            profile_id=notification.recipient_profile.id).values_list(
                "value", flat=True))

    if notification.recipient_email:
        sane_exists = ProfileEmail.all_sane().filter(
            value=notification.recipient_email).exists()
        exists_generally = ProfileEmail.objects.filter(
            value=notification.recipient_email).exists()
        if sane_exists or not exists_generally:
            all_emails.append(notification.recipient_email)

    if not all_emails:
        if notification.recipient_profile:
            raise EmailNotFoundException(
                message="", profile_id=notification.recipient_profile.id)
        else:
            raise UnspecifiedRecipientException()

    return all_emails
Пример #3
0
def get_sender_email(notification, fallback='*****@*****.**'):
    from_email = None
    if notification.sender_profile:
        collect_contact_info_for_profile(notification.sender_profile)
        from_email = ProfileEmail.to_reach(notification.sender_profile_id)
        if from_email:
            from_email = from_email.value

    return from_email or notification.sender_email or fallback
def is_user_awaiting_verification(user):
    try:
        profile = Profile.objects.filter(user=user,
                                         queued_for_deletion=False).first()

        collect_contact_info_for_profile(profile)
        email = ProfileEmail.to_reach(profile.id, strict=True)

        return profile and email and EmailAddress.objects.filter(
            email=email, verified=False).exists()
    except Exception:
        return False
Пример #5
0
    def get(self, request, icims_job_id):
        employer_job = EmployerJob.objects.get(id=icims_job_id)
        employer_user = EmployerUser.objects.filter(
            user=request.user, employer=employer_job.employer).first()
        if employer_user is None:
            return None

        candidates_who_have_accepted = (EmployerCandidate.objects.filter(
            employer_job=employer_job,
            responded=True, accepted=True).select_related(
                'profile', 'profile__state').order_by('profile_id'))

        fieldnames = [
            "profile_id", "first_name", "last_name", "email", "phone", "city",
            "state"
        ]
        with io.StringIO() as file_out:
            csv_out = csv.DictWriter(file_out, fieldnames=fieldnames)

            # print header
            csv_out.writerow({key: key for key in fieldnames})

            for candidate in candidates_who_have_accepted:
                profile = candidate.profile
                collect_contact_info_for_profile(profile)
                e = ProfileEmail.to_reach(profile.id)
                p = ProfilePhoneNumber.to_reach(profile.id)
                dictionary = {
                    "profile_id": profile.id,
                    "first_name": profile.first_name,
                    "last_name": profile.last_name,
                    "email": e.value if e else None,
                    "phone": p.value if p else None,
                    "city": profile.city,
                    "state": profile.state.state_code,
                }
                csv_out.writerow(dictionary)

            response = HttpResponse(file_out.getvalue(),
                                    content_type="text/plain")

            # make browser download the file
            response[
                'Content-Disposition'] = "attachment; filename=candidates_{}.csv".format(
                    employer_job.id)

            record_event(
                request.user, EventActions.employer_job_export, {
                    "employer_user_id": employer_user.id,
                    "icims_job_id": employer_job.id
                })

            return response
Пример #6
0
def _test_auto_respond_functions(is_bakround_employee):
    test_candidate_queue.set_up_test(is_bakround_employee)

    employer_user = EmployerUser.objects.first()
    employer_job = EmployerJob.objects.first()

    user = employer_user.user
    user.first_name, user.last_name = "Bob", "Loblaw"
    user.save()

    assert full_name_of_employer_user(employer_user) == "Bob Loblaw"

    assert get_recruiter_for_job(employer_job) == employer_user

    profile = Profile.objects.first()
    collect_contact_info_for_profile(profile)
    candidate = EmployerCandidate(profile=profile,
                                  employer_job=employer_job,
                                  employer_user=employer_user)
    candidate.save()

    # First, test the case where old data is used.

    cd = ProfileEmail(profile=profile, value="*****@*****.**")
    cd.save()
    assert get_email_address_for_responding_candidate(candidate) is None

    NotificationRecipientEvent(action="open", email=cd.value).save()
    collect_email_data(cd)
    assert get_email_address_for_responding_candidate(candidate) == cd.value

    NotificationRecipientEvent(action="unsubscribe", email=cd.value).save()
    collect_email_data(cd)
    assert get_email_address_for_responding_candidate(candidate) is None

    # Then, test the case where new data is used.

    e = ProfileEmail(profile=profile, value="*****@*****.**")
    e.save()
    assert get_email_address_for_responding_candidate(candidate) is None

    e.opens = True
    e.save()
    assert get_email_address_for_responding_candidate(candidate) == e.value

    e.unsubscribed = True
    e.save()
    assert get_email_address_for_responding_candidate(candidate) is None
Пример #7
0
    def extract_contact_info_from_resume(self, profile, profile_data):
        collect_contact_info_for_profile(profile)

        # Since this will eventually be moved to its own record,
        # it goes here. The way it's handled will ultimately resemble the email
        # phone number fields below.
        profile.street_address = profile.street_address or profile_data.street_address or None

        for value in profile_data.emails:
            add_contact(ProfileEmail, value, profile.id, True)

        for value in profile_data.phones:
            add_contact(ProfilePhoneNumber, value, profile.id, True)

        self.logger.info(
            "Updated contact information for Profile id {}".format(profile.id))
def test_collect_contact_info_for_profile():
    p = Profile(email="*****@*****.**", phone="phonenumber")
    p.save()

    ProfileExternalData(emails=["*****@*****.**"], phones=["ring"], output={"foo": "foo"}, provider="pipl", profile=p).save()
    ProfileExternalData(emails=["*****@*****.**"], phones=["rang"], output={"foo": "bar"}, provider="whitepages", profile=p).save()

    collect_contact_info_for_profile(p)

    p = Profile.objects.get(id=p.id)

    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p, is_correct_person=True).first()
    assert ProfilePhoneNumber.objects.filter(value="phonenumber", profile=p, is_correct_person=True).first()
    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p).first()
    assert ProfileEmail.objects.filter(value="*****@*****.**", profile=p).first()
    assert not p.email
    assert not p.phone

    rlookup_one = ProfileReverseLookup.objects.filter(provider="pipl").first()
    rlookup_two = ProfileReverseLookup.objects.filter(provider="whitepages").first()

    assert rlookup_one and rlookup_one.output["foo"] == "foo"
    assert rlookup_two and rlookup_two.output["foo"] == "bar"
Пример #9
0
    def post(self, request):
        template_name = "notifications/page_after_candidate_accepts.html"
        employer_candidate_guid = request.POST['employer_candidate_guid']
        message = request.POST['message']

        candidate = EmployerCandidate.objects.get(guid=employer_candidate_guid)

        new_response = EmployerCandidateResponse(response=message)
        new_response.save()

        # TODO: delete the old response.

        candidate.response = new_response
        candidate.save(update_fields=['response'])

        new_email = request.POST.get('email')
        new_phone = request.POST.get('phone')

        collect_contact_info_for_profile(candidate.profile)

        if new_email:
            add_contact(ProfileEmail, new_email, candidate.profile.id, True)

        if new_phone:
            add_contact(ProfilePhoneNumber, new_phone, candidate.profile.id,
                        True)

        # Send a notification to the employer if they asked this candidate to update their info
        if candidate.contact_info_requested:
            emails.CandidateUpdatedInfo().send(employer_candidate=candidate)
            message = "Thanks for updating your info! The recruiter will contact you shortly."
        else:
            emails.CandidateAccepted().send(employer_candidate=candidate)
            message = "Your message has been sent!"

        messages.success(request, message)
        return redirect('/candidate/accept/{}'.format(candidate.guid))
Пример #10
0
def get_email_address_for_responding_candidate(candidate):
    # Turning strict on excludes all emails that didn't open emails we sent them.
    collect_contact_info_for_profile(candidate.profile)
    pe = ProfileEmail.to_reach(candidate.profile, strict=True)
    if pe: return pe.value
    return None
def profile_to_json_icims(profile_id,
                          icims_job_id=None,
                          hide_details=False,
                          hide_bscore=False,
                          hide_job=False,
                          hide_profile_id=True):

    details_visible = not hide_details

    profile = Profile.objects.get(id=profile_id)

    certification_set = (profile.profilecertification_set.extra(
        select={
            "issued_date_non_null": "COALESCE(issued_date, '1970-01-01')"
        }).order_by('-issued_date_non_null', 'certification_name'))

    emails = []
    phones = []
    if details_visible:
        collect_contact_info_for_profile(profile)
        phones_raw = list(
            ProfilePhoneNumber.objects.filter(
                profile_id=profile_id).values_list('value', flat=True))
        phones = list(filter(bool, map(format_phone_number, phones_raw)))
        emails = list(ProfileEmail.all_sane().filter(
            profile_id=profile_id).values_list('value', flat=True))

    job_id = None
    job_name = None

    if details_visible and not hide_job:
        if icims_job_id:
            job = IcimsJobData.objects.get(pk=icims_job_id)
            job_id = job.id
            job_name = job.job_title
        elif icims_job_id:
            job = IcimsJobData.objects.get(pk=icims_job_id)
            job_id = job.job_id
            job_name = job.job_title
        else:
            mapping = ProfileJobMapping.objects.filter(
                profile_id=profile_id).order_by("id").first()
            if mapping:
                job_id = mapping.job_id
                job_name = mapping.job.job_name

    if profile.last_updated_date:
        last_updated_date_display = profile.last_updated_date.date().strftime(
            "%m/%d/%y")
    else:
        last_updated_date_display = None

    score = None
    if details_visible and not hide_bscore:
        score = int((Score.objects.filter(
            profile_id=profile_id,
            job_id=job_id).order_by('-date_created').values_list(
                'score_value', flat=True).first()) or 0) or None

    name = None
    if profile.name_verification_completed and (profile.first_name
                                                or profile.last_name):
        name = ' '.join(filter(bool, [profile.first_name, profile.last_name]))

    if not name:
        name = make_initials_for_profile_id(profile.id)

    print("retuning-----------------")
    return {
        "profile":
        profile,
        "name":
        name,
        "job_name":
        job_name,
        "emails":
        emails,
        "phones":
        phones,
        "experience_set":
        list((profile.profileexperience_set.order_by(
            '-is_current_position',
            F('end_date').desc(nulls_first=True),
            F('start_date').desc(nulls_last=True)).select_related('state'))),
        "education_set":
        list(
            map(
                annotate_education_record,
                profile.profileeducation_set.order_by(
                    F('degree_date').desc(nulls_last=True),
                    '-start_date').select_related('state', 'degree_major',
                                                  'degree_type',
                                                  'degree_name'))),
        "certification_set":
        list(certification_set),
        "last_updated_date_display":
        last_updated_date_display,
        "score":
        score,
        "show_profile_id":
        details_visible and not hide_profile_id
    }
Пример #12
0
    def go(self, request, params):
        page = params.get("page", 0)
        page_size = params.get("page_size", 20)

        requests = ProfileVerificationRequest.objects.filter(
            verified=False, metadata__bkrnd_ecid__isnull=False)

        fltr = params.get("filter", 'all')
        if fltr == "contacted":
            requests = requests.filter(contacted=True, responded=False)
        elif fltr == "not_contacted":
            requests = requests.filter(contacted=False)
        elif fltr == "responded":
            requests = requests.filter(contacted=True, responded=True)
        elif fltr == "pending_action":
            requests = requests.filter(pending_action=True)
        elif fltr == "broken":
            requests = requests.filter(broken=True)
        elif fltr == "unreachable":
            requests = requests.filter(unreachable=True)

        url_qs = ProfileResume.objects.filter(
            profile_id=OuterRef("profile_id")).order_by("-id").values_list(
                "url", flat=True)[:1]
        requests = requests.annotate(
            resume_url=Subquery(url_qs)).order_by('-id')

        total_requests = requests.count()

        requests = requests[(page * page_size):((page * page_size) +
                                                page_size)]

        json_requests = []
        for r in requests:
            collect_contact_info_for_profile(r.profile)

            if 'bkrnd_ecid' in r.metadata:
                ejid = EmployerCandidate.objects.filter(
                    id=int(r.metadata["bkrnd_ecid"])).first()
                if ejid:
                    ejid = ejid.employer_job_id
            else:
                ejid = EmployerCandidate.objects.filter(
                    profile_id=r.profile_id,
                    employer_job_id__isnull=False,
                    employer_job__employer_id__isnull=False,
                    contacted=True).order_by('-id').values_list(
                        'employer_job_id', flat=True).first()

            res = {
                "id": r.id,
                "resume_url": r.resume_url,
                "status": pvr_to_status_json(r),
                "profile": profile_to_json(r.profile)
            }

            if ejid:
                ej = EmployerJob.objects.get(id=ejid)
                res["job"] = {
                    'id': ej.id,
                    'title': ej.job_name,
                    'generic_title': ej.job.job_name,
                    'company_name': ej.employer.company_name
                }

            json_requests.append(res)

        count_qs = ProfileVerificationRequest.objects.filter(verified=False)

        return {
            'requests':
            json_requests,
            'total_requests':
            total_requests,
            'stats': [{
                'name': 'Unverified',
                'value': count_qs.count()
            }, {
                'name': "Contacted",
                'value': count_qs.filter(contacted=True).count()
            }, {
                'name': "Not Contacted",
                'value': count_qs.filter(contacted=False).count()
            }, {
                'name': "Broken",
                'value': count_qs.filter(broken=True).count()
            }, {
                'name': "Unreachable",
                'value': count_qs.filter(unreachable=True).count()
            }]
        }