def update_language(): # handle authetication problems handle_authentication(False) form = Users.forms.Languages() fields = extract_fields(form) if request.method == 'GET': # prefill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # update user attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_language.html', title="Langues", form=form, fields=fields)
def update_localisation(): # handle authetication problems handle_authentication(False) form = Users.forms.Localisation() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # if needed add the town to Town table if form.town.data not in Town.list_all(): form.town.data = form.town.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(Town(town=form.town.data)) # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_localisation.html', title="Localisation", form=form, fields=fields, country_list=Country.list_all(), town_list=Town.list_all())
def update_resume(n): # handle authetication problems handle_authentication(False) form = Users.forms.Resume() fields = extract_fields(form) if request.method == 'GET': # prefill the form pass else: if form.validate_on_submit(): # update user info _resume_doc = save_resume(form.resume_doc.data) setattr(current_user, f"resume{n}_doc", _resume_doc) if form.resume_name.data: setattr(current_user, f"resume{n}_name", form.resume_name.data) else: setattr(current_user, f"resume{n}_name", f"my_resume_{n}") return commit_flash_redirect('users.manage_user') else: if form.errors: flash_all_errors(form) return render_template('user/update/update_resume.html', title="CVs", fields=fields, form=form)
def update_expectation(): # handle authetication problems handle_authentication(False) form = Users.forms.Expectation() fields = extract_fields(form) if request.method == 'GET': # prefill the form form.employed.data = current_user.employed form.search.data = current_user.search form.order.data = current_user.order form.automation.data = current_user.automation else: if form.validate_on_submit(): # update user info current_user.employed = form.employed.data current_user.sub_employed = form.sub_employed.data current_user.search = form.search.data current_user.order = form.order.data current_user.automation = form.automation.data return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_expectation.html', title="Attentes", fields=fields, form=form)
def update_plateform(plateform): plateform_name = plateform # handle authetication problems handle_authentication(False) form = Plateforms.forms.Update() fields = extract_fields(form) plateform = getattr( Plateforms.tables, plateform_name).query.filter_by(user_id=current_user.id).first() if request.method == 'GET': if plateform: for field in fields: getattr(form, field).data = getattr(plateform, field) else: if form.validate_on_submit(): if not plateform: plateform = getattr(Plateforms.tables, plateform_name)(user_id=current_user.id) db.session.add(plateform) db.session.commit() if form.account.data == "Oui": form.sub_account.data = "Oui" plateform = getattr(Plateforms.tables, plateform_name).query.filter_by( user_id=current_user.id).first() for field in fields: setattr(plateform, field, getattr(form, field).data) db.session.commit() # if form.connection.data != "On": # flash(f"Sorry did not allow to login to {plateform}", # "danger") # return redirect(url_for("users.manage_user")) for i in ["autorisation", "good_user", "edhunt_integrity"]: if getattr(form, i).data != "Oui": flash( f"Sorry you must accept credentials to login to {plateform_name}", "danger") return redirect(url_for("plateforms.manage_plateforms")) return commit_flash_redirect('plateforms.manage_plateforms') else: flash_all_errors(form) return render_template('plateform/update_plateform.html', title=plateform_name, form=form, fields=fields)
def update_work_experience(): # handle authetication problems handle_authentication(False) form = Users.forms.WorkExperience() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # if needed add the comapny and job to relative tables if form.company.data not in Company.list_all(): form.company.data = form.company.data.upper().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") db.session.add(Company(company=form.company.data)) db.session.commit() if form.job.data not in Job.list_all(): form.job.data = form.job.data.capitalize().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") db.session.add(Job(job=form.job.data)) db.session.commit() if form.key_words.data: kwords = form.key_words.data kwords = kwords.lower().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") kwords = ", ".join([i.strip() for i in kwords.split(",")]) form.key_words.data = kwords # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) db.session.commit() return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_work_experience.html', title="Experience professionnelle", form=form, fields=fields, company_list=Company.list_all(), job_list=Job.list_all())
def update_diploma(): # handle authetication problems handle_authentication(False) form = Users.forms.Diploma() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # handle town and school if needed if form.diploma_town.data not in Town.list_all(): form.diploma_town.data = form.diploma_town.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(Town(town=form.diploma_town.data)) if form.diploma_school.data not in School.list_all(): form.diploma_school.data = form.diploma_school.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(School(school=form.diploma_school.data)) # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_diploma.html', title="DiplĂ´ma", form=form, fields=fields, town_list=Town.list_all(), school_list=School.list_all())