def other_form(): """ Allow a recruiter to make another demand. """ form = forms.OfficeOtherRequestForm(data=request.values) if form.validate_on_submit(): recruiter_message = models.OtherRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid() ) mail_content = mail.generate_other_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') params = request.args.to_dict() params.update({ 'custom_ga_pageview': '/recruteur/other/success', }) return redirect(url_for('contact_form.success', **params)) return render_template( 'contact_form/form.html', form=form, title='Autre demande', params=urlencode(get_office_identification_data()), use_lba_template=is_recruiter_from_lba(), show_required_disclaimer=True, custom_ga_pageview='/recruteur/other/other', )
def delete_form(form): if form.validate_on_submit(): recruiter_message = models.RemoveRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid()) mail_content = mail.generate_delete_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') else: redirect_params = get_success_value() return render_template( 'contact_form/success_message.html', title="Merci pour votre message", use_lba_template=is_recruiter_from_lba(), site_name=redirect_params.get('site_name'), email=redirect_params.get('email'), home_url=redirect_params.get('home_url'), action_form_url=url_for('contact_form.ask_action', **request.args), custom_ga_pageview='/recruteur/delete/success', ) return render_template( 'contact_form/form.html', title='Supprimer mon entreprise', form=form, params=extract_recruiter_data(), use_lba_template=is_recruiter_from_lba(), custom_ga_pageview='/recruteur/delete/delete', )
def delete_form(): """ Allow a recruiter to remove his company from LBB/LBA. """ form = forms.OfficeRemoveForm(data=request.values) if form.validate_on_submit(): recruiter_message = models.RemoveRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid() ) mail_content = mail.generate_delete_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') params = request.args.to_dict() params.update({ 'custom_ga_pageview': '/recruteur/delete/success', }) return redirect(url_for('contact_form.success', **params)) return render_template('contact_form/form.html', title='Supprimer mon entreprise', form=form, params=urlencode(get_office_identification_data()), use_lba_template=is_recruiter_from_lba(), custom_ga_pageview='/recruteur/delete/delete', )
def update_jobs_form(form): try: office = get_office_from_siret(request.args['siret']) except NoResultFound: flash(unknown_siret_message(), 'error') return redirect(url_for('contact_form.change_info')) office_romes = mapping_util.romes_for_naf(office.naf) rome_fields = [] for rome in office_romes: # Retrieve old values current_values = dict(request.form).get(rome.code, ['lbb', 'lba']) rome_fields.append({ 'code': rome.code, 'name': rome.name, 'current_values': current_values }) if form.validate_on_submit(): recruiter_message = models.UpdateJobsRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid()) mail_content = mail.generate_update_jobs_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') else: redirect_params = get_success_value() return render_template( 'contact_form/success_message.html', title="Merci pour votre message", use_lba_template=is_recruiter_from_lba(), site_name=redirect_params.get('site_name'), email=redirect_params.get('email'), home_url=redirect_params.get('home_url'), rome_fields=rome_fields, suggest_update_coordinates=True, params=extract_recruiter_data(), action_form_url=url_for('contact_form.ask_action', **request.args), custom_ga_pageview='/recruteur/update_jobs/success', ) return render_template( 'contact_form/change_job_infos.html', title='Demande de modification des métiers', form=form, params=extract_recruiter_data(), use_lba_template=is_recruiter_from_lba(), manually_added_jobs=extract_manually_added_jobs(office), rome_fields=rome_fields, custom_ga_pageview='/recruteur/update_jobs/update_jobs', )
def sendMail(mail_content, subject): ''' This function will send an email to us and retry in case of failure With 2 attempts - i.e. 1 retry, the wait time will be 5s at worst ''' for attempt in range(MAX_ATTEMPTS): try: mail.send_mail(mail_content=mail_content, subject=subject) except MailjetAPIError as e: logger.exception(e) if attempt < MAX_ATTEMPTS - 1: time.sleep(5) else: break else: logger.critical('Mail not sent (to settings.TO_EMAIL)', subject, mail_content) flash(generate_fail_flash_content(), 'error')
def update_jobs_form(): """ Allow a recruiter to add or delete ROME codes related to his company. """ # Use POST params if available, GET params otherwise. form_data = request.form or request.args.copy() try: office = models.Office.query.filter(models.Office.siret == form_data['siret']).one() except NoResultFound: flash(unknown_siret_message(), 'error') return redirect(url_for('contact_form.change_info')) if request.method == 'GET': # Prepare form's initial data. romes_to_boost = office.romes_codes romes_alternance_to_boost = office.romes_codes extra_romes_to_add = set() extra_romes_alternance_to_add = set() office_update = OfficeAdminUpdate.query.filter(OfficeAdminUpdate.sirets == office.siret).first() if office_update: if office_update.romes_to_boost: romes_to_boost = set(OfficeAdminUpdate.as_list(office_update.romes_to_boost)) extra_romes_to_add = romes_to_boost - office.romes_codes if office_update.romes_alternance_to_boost: romes_alternance_to_boost = set(OfficeAdminUpdate.as_list(office_update.romes_alternance_to_boost)) extra_romes_alternance_to_add = romes_alternance_to_boost - office.romes_codes form_data['romes_to_keep'] = romes_to_boost form_data['romes_alternance_to_keep'] = romes_alternance_to_boost else: # Those form fields are defined outside of the form class, we use `request.form` to get them. extra_romes_to_add = set(request.form.getlist('extra_romes_to_add')) extra_romes_alternance_to_add = set(request.form.getlist('extra_romes_alternance_to_add')) form = forms.OfficeUpdateJobsForm(data=form_data, office=office) if form.validate_on_submit(): recruiter_message = models.UpdateJobsRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid() ) mail_content = mail.generate_update_jobs_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') params = request.args.to_dict() params.update({ 'custom_ga_pageview': '/recruteur/update_jobs/success', 'suggest_update_coordinates': '1', }) return redirect(url_for('contact_form.success', **params)) extra_added_jobs = [ { 'rome_code': rome_code, 'label': settings.ROME_DESCRIPTIONS[rome_code], 'lbb': rome_code in extra_romes_to_add, 'lba': rome_code in extra_romes_alternance_to_add, } for rome_code in extra_romes_to_add | extra_romes_alternance_to_add ] return render_template('contact_form/change_job_infos.html', title='Demande de modification des métiers', form=form, params=urlencode(get_office_identification_data()), use_lba_template=is_recruiter_from_lba(), extra_added_jobs=extra_added_jobs, custom_ga_pageview='/recruteur/update_jobs/update_jobs', )
def update_coordinates_form(): """ Allow a recruiter to update his company's coordinates. """ form_data = request.values try: office = models.Office.query.filter(models.Office.siret == form_data['siret']).one() except NoResultFound: flash(unknown_siret_message(), 'error') return redirect(url_for('contact_form.change_info')) form = forms.OfficeUpdateCoordinatesForm(data=form_data) # Fill form with form value (or office value by default) form.new_contact_mode.data = request.form.get( 'new_contact_mode', CONTACT_MODES_LABEL_TO_FORM_VALUE.get(office.contact_mode, '') ) form.new_website.data = request.form.get('new_website', office.website) form.new_email.data = request.form.get('new_email', office.email) form.new_phone.data = request.form.get('new_phone', office.phone) form.social_network.data = request.form.get('social_network', office.social_network) form.new_phone_alternance.data = request.form.get('new_phone_alternance', office.phone_alternance) form.new_email_alternance.data = request.form.get('new_email_alternance', office.email_alternance) if form.validate_on_submit(): form_valid = True # If a recruiter choose a contact_mode, the associated field became required contact_mode = form.new_contact_mode.data if contact_mode == 'website' and not form.new_website.data: flash(ERROR_CONTACT_MODE_MESSAGE.format('Via votre site internet', 'Site Internet'), 'error') form_valid = False elif contact_mode == 'phone' and not form.new_phone.data: flash(ERROR_CONTACT_MODE_MESSAGE.format('Par téléphone', 'Téléphone'), 'error') form_valid = False elif contact_mode == 'email' and not form.new_email.data: flash(ERROR_CONTACT_MODE_MESSAGE.format('Par email', 'Email recruteur'), 'error') form_valid = False if form_valid: recruiter_message = models.UpdateCoordinatesRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid() ) mail_content = mail.generate_update_coordinates_mail(form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') params = request.args.to_dict() params.update({ 'custom_ga_pageview': '/recruteur/update_coordinates/success', 'suggest_update_jobs': '1', }) return redirect(url_for('contact_form.success', **params)) return render_template('contact_form/form.html', title='Modifier ma fiche entreprise', form=form, params=urlencode(get_office_identification_data()), use_lba_template=is_recruiter_from_lba(), show_entreprise_page=True, show_coordinates_disclaimer=True, custom_ga_pageview='/recruteur/update_coordinates/update_coordinates', )
def update_coordinates_form(form): try: office = get_office_from_siret(request.args['siret']) except NoResultFound: flash(unknown_siret_message(), 'error') return redirect(url_for('contact_form.change_info')) # Fill form with form value (or office value by default) form.new_contact_mode.data = request.form.get( 'new_contact_mode', CONTACT_MODES_LABEL_TO_FORM_VALUE.get(office.contact_mode, '')) form.new_website.data = request.form.get('new_website', office.website) form.new_email.data = request.form.get('new_email', office.email) form.new_phone.data = request.form.get('new_phone', office.phone) form.social_network.data = request.form.get('social_network', office.social_network) form.new_phone_alternance.data = request.form.get('new_phone_alternance', office.phone_alternance) form.new_email_alternance.data = request.form.get('new_email_alternance', office.email_alternance) if form.validate_on_submit(): form_valid = True # If a recruiter choose a contact_mode, the associated field became required contact_mode = form.new_contact_mode.data if contact_mode == 'website' and not form.new_website.data: flash( ERROR_CONTACT_MODE_MESSAGE.format('Via votre site internet', 'Site Internet'), 'error') form_valid = False elif contact_mode == 'phone' and not form.new_phone.data: flash( ERROR_CONTACT_MODE_MESSAGE.format('Par téléphone', 'Téléphone'), 'error') form_valid = False elif contact_mode == 'email' and not form.new_email.data: flash( ERROR_CONTACT_MODE_MESSAGE.format('Par email', 'Email recruteur'), 'error') form_valid = False if form_valid: recruiter_message = models.UpdateCoordinatesRecruiterMessage.create_from_form( form, is_certified_recruiter=peam_recruiter.is_certified_recruiter(), uid=peam_recruiter.get_recruiter_uid()) mail_content = mail.generate_update_coordinates_mail( form, recruiter_message) try: mail.send_mail(mail_content, get_subject()) except MailNoSendException as e: logger.exception(e) flash(generate_fail_flash_content(), 'error') else: redirect_params = get_success_value() return render_template( 'contact_form/success_message.html', title="Merci pour votre message", use_lba_template=is_recruiter_from_lba(), site_name=redirect_params.get('site_name'), email=redirect_params.get('email'), home_url=redirect_params.get('home_url'), suggest_update_jobs=True, params=extract_recruiter_data(), action_form_url=url_for('contact_form.ask_action', **request.args), custom_ga_pageview='/recruteur/update_coordinates/success', ) return render_template( 'contact_form/form.html', title='Modifier ma fiche entreprise', form=form, params=extract_recruiter_data(), use_lba_template=is_recruiter_from_lba(), show_entreprise_page=True, show_coordinates_disclaimer=True, custom_ga_pageview='/recruteur/update_coordinates/update_coordinates', )