def create_user(campaign, user_params, request, is_mobile, signup_form=None): """ Args: campaign: obj user_params: Dict with user params request: HTTP is_mobile: Boolean signup_form: the form with which it did sign up Returns: Creates a new user on the DB. """ user = User(**user_params) user.save() # Saves here to get an id if signup_form: add_auth_and_login(signup_form, user, request) update_resource(request, user, 'curriculum_url', 'resumes') user.save() # Starts on Backlog default state, when no evaluation has been done. candidate = Candidate(campaign=campaign, user=user) candidate.save() email_body_name = 'user_signup_email_body' if is_mobile: email_body_name += '_mobile' email_sender.send(objects=candidate, language_code=request.LANGUAGE_CODE, body_input=email_body_name, subject=_('Welcome to PeakU')) return user
def add_candidate_to_campaign(request, candidate): """ Adds candidate to another campaign. Args: request: A HTTP request candidate: Candidate object Returns: Boolean indicating whether a new candidate was added """ # Updates latest changes, first. update_candidate_manually(request, candidate) selected_campaign_id = int( request.POST.get('{}_selected_campaign'.format(candidate.id))) if selected_campaign_id == cts.CAMPAIGN_ID_NULL or user_in_campaign( candidate.user_id, selected_campaign_id): return False else: # Starts in Backlog on the new campaign. # TODO: can add logic to new at a later stage, if tests are already passed. Candidate(user_id=candidate.user_id, campaign_id=selected_campaign_id, state=State.objects.get(code='P')).save() return True
def simple_filter(campaign, users): """ Filters by: 1. city 2. work area 3. not having job :param campaign: a Campaign object :param users: list of User objects :return: list of candidates """ candidates = [Candidate(user=u, campaign=campaign, pk=1) for u in users] candidates = [ c for c in candidates if non_null_equal(c.user.city, c.campaign.city) and non_null_equal(c.user.work_area, c.campaign.work_area) and non_null_lte(campaign.get_very_low_salary(), c.user.salary) and non_null_gte(campaign.get_very_high_salary(), c.user.salary) ] # Cuts top candidates because its too expensive a job filter. candidates = candidates[:MAX_MATCHES] return [ c.user for c in candidates if not common.user_has_been_recommended(c.user) ]
def add_candidates_to_campaign(campaign, users, state_code): state = State.objects.get(code=state_code) candidates = Candidate.objects.bulk_create( [Candidate(campaign=campaign, user=u, state=state) for u in users]) bulk_save(candidates) return candidates
def update_user(campaign, user, user_params, request, signup_form=None): """ Args: campaign: campaign user: Obj user_params: dict with fields of a User obj request: HTTP signup_form: sign up form, it will add a AuthUser Returns: None """ if signup_form: add_auth_and_login(signup_form, user, request) common.update_object(user, user_params) user.updated_at = datetime.utcnow() user.save() update_resource(request, user, 'curriculum_url', 'resumes') update_resource(request, user, 'photo_url', 'candidate_photo') update_resource(request, user, 'brochure_url', 'candidate_brochure') candidate = candidate_if_exists(campaign, user) if not candidate: Candidate(campaign=campaign, user=user).save() return user
def add_missing_tests(user, campaigns): """ Will add to temp properties to the campaigns, in order to show tests that are completed or missing :param user: :param campaigns: :return: """ if user: for campaign in campaigns: prospective_candidate = Candidate(user=user, campaign=campaign) high_scores = test_module.get_high_scores(prospective_candidate, campaign) campaign.passed_tests = [s.test for s in high_scores] campaign.missing_tests = test_module.get_missing_tests( prospective_candidate, campaign, high_scores=high_scores)
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))
def update_candidate_state(campaign, user, interview_obj, question_number): """ If previous_question was the last question then it updates the candidate state to DIS (Did Interview in Standby) Args: campaign: obj user: obj interview_obj: Interview Object question_number: int Returns: """ if question_number - 1 > 0: # cannot ask for zero or negative questions previous_question = interview_obj.questions.get(order=question_number-1) if on_last_question(interview_obj, previous_question): try: candidate = Candidate.objects.get(user=user, campaign=campaign) candidate.state = State.objects.get(code='DI') candidate.save() except ObjectDoesNotExist: # the object hasn't been created yet, creates it. Candidate(campaign=campaign, user=user, state=State.objects.get(code='DI')).save()
def get_top_users_with_log(campaign): """ This function is slow but has a amazing log of what is happening with the filter. Very helpful to understand prospects, but extremly slow... :param campaign: :return: """ # TODO: this feature only supports Spanish. search_text = campaign.get_search_text() search_array = search_module.get_word_array_lower_case_and_no_accents( search_text) #search_array += search_module.add_related_words(search_array) search_log = SearchLog() search_log.save() search_log.campaign = campaign # Tests #users_tests = get_users_from_tests(campaign) #search_log.users_from_tests.add(*users_tests) #users = users_tests users = [] # Traditional Search: hard to scale #users_search = search_module.get_matching_users(search_array) #search_log.users_from_search.add(*users_search) #users += users_search # ES users_es = User.objects.filter(pk__in=get_user_ids_from_es(search_array)) search_log.users_from_es.add(*users_es) users += users_es # ALL search_log.all_users.add(*users) # FILTERS candidates = [Candidate(user=u, campaign=campaign, pk=1) for u in users] # CITY FILTER candidates = [ c for c in candidates if non_null_equal(c.user.city, c.campaign.city) ] search_log.after_city_filter.add(*[c.user for c in candidates]) # WORK AREA SEGMENT FILTER candidates = [ c for c in candidates if non_null_equal( c.user.get_work_area_segment(), campaign.get_work_area_segment()) ] search_log.after_work_area_filter.add(*[c.user for c in candidates]) # SALARY FILTER candidates = [ c for c in candidates if non_null_lte(campaign.get_very_low_salary(), c.user.salary) and non_null_gte(campaign.get_very_high_salary(), c.user.salary) ] search_log.after_salary_filter.add(*[c.user for c in candidates]) # BACK TO USER users = [c.user for c in candidates] # Cuts top candidates first, because its too expensive a job filter. users = users[:MAX_MATCHES] search_log.after_cap_filter.add(*users) users = [u for u in users if not common.user_has_been_recommended(u)] search_log.after_recommended_filter.add(*users) users = search_module.remove_duplicates(users) search_log.after_duplicates_filter.add(*users) search_log.save() return users