Example #1
0
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)
Example #2
0
def update_user():

    handle_authentication(False)

    form = Users.forms.Update()
    fields = extract_fields(form)
    if request.method == 'GET':
        # prefill the form
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.password.data = ""
        form.confirm_password.data = ""
    else:
        if form.validate_on_submit():
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            current_user.username = form.username.data
            current_user.email = form.email.data
            current_user.password = hashed_password
            db.session.commit()
            flash('Your account has been modified! Please re-log in',
                  'success')
            logout_user()
            return redirect(url_for('users.login'))
        else:
            flash_all_errors(form)

    return render_template('user/update/update_user.html',
                           title='Compte',
                           fields=fields,
                           form=form)
Example #3
0
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)
Example #4
0
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)
Example #5
0
def questionnaire_1(token):

    form = MainForms.Form_1()
    fields = extract_fields(form)

    if request.method == 'GET':
        pass
    else:

        if form.validate_on_submit():
            if not token:
                token = token_hex(16)
                quest = Questionnaire(token=token)
                db.session.add(quest)
                db.session.commit()
            else:
                quest = Questionnaire.query.filter_by(token=token).first()
                if not quest:
                    flash("Désolé, une erreur c'est produite", "danger")
                    return redirect(url_for("main.home"))

            for field in fields:
                setattr(quest, field, getattr(form, field).data)
            db.session.commit()

            return redirect(url_for("main.questionnaire_2", token=token))
        else:
            flash_all_errors(form)

    return render_template('main/questionnaire_1.html',
                           title="Inscription 1/6",
                           form=form,
                           token=token,
                           text=MainText.questionnaire.q1,
                           back=None)
Example #6
0
def questionnaire_5(token):

    quest = Questionnaire.query.filter_by(token=token).first()
    if not quest:
        flash("Désolé, une erreur c'est produite", "danger")
        return redirect(url_for("main.home"))
    form = MainForms.Form_5()
    fields = extract_fields(form)

    if request.method == 'GET':
        pass
    else:

        if form.validate_on_submit():
            for field in fields:
                setattr(quest, field, getattr(form, field).data)
            db.session.commit()

            # flash("Super Merci!", "success")
            return redirect(url_for("main.questionnaire_6", token=token))
        else:
            flash_all_errors(form)

    return render_template('main/questionnaire_5.html',
                           title="Inscription 5/6",
                           form=form,
                           token=token,
                           text=MainText.questionnaire.q5,
                           back="4")
Example #7
0
def update_searched_status(search_id):

    # handle connections problems
    handle_authentication(False)
    search = Search.query.filter_by(id=search_id).first()
    # authetication problem
    if current_user.id != search.user_id:
        flash("sorry this is not your search, you are not allowed", "danger")
        return redirect(url_for("main.edhunt"))

    form = SearchsForms.Status()
    fields = extract_fields(form)
    if request.method == 'GET':
        # prefill all fields
        for field in fields:
            k = getattr(form, field)
            k.data = getattr(search, field)
    else:
        if form.validate_on_submit():
            # update user attrs
            for field in fields:
                d = getattr(form, field).data
                if isinstance(d, list):
                    d = ", ".join(d)
                setattr(search, field, d)
            db.session.commit()
            flash("Search updated", "success")
            return redirect(
                url_for('searchs.manage_search', search_id=search.id))
        else:
            flash_all_errors(form)
    return render_template('search/update/update_searched_status.html',
                           title="Update Statuts",
                           form=form,
                           search_id=search.id)
Example #8
0
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())
Example #9
0
def create_search():

    # handle connections problems
    handle_authentication(False)
    # form and fields
    form = SearchsForms.Create()
    # fields = extract_fields(form)
    if request.method == 'GET':
        pass
    else:
        if form.validate_on_submit():
            # if needed add the town to Town table
            for i in (1, 2, 3, 4, 5):
                town = getattr(form, f"town_{i}").data
                if town not in Town.list_all():
                    town = town.capitalize()\
                        .strip().replace("  ", " ").replace("  ", " ")
                    db.session.add(Town(town=town))

            search = Search(user_id=current_user.id)
            # upadte user attrs
            search.name = form.name.data
            search.mob = form.mob.data
            for feat in ["country", "departement", "region", "town"]:
                _data = [
                    getattr(form, f"{feat}_{i}").data for i in [1, 2, 3, 4, 5]
                ]
                setattr(search, feat, ", ".join([i for i in _data if i]))
            form.key_words.data = form.key_words.data.strip().upper()\
                .replace("-", " ").replace("  ", " ").replace("  ", " ")
            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
            search.key_words = form.key_words.data
            db.session.add(search)
            db.session.commit()
            flash("search updated", "success")
            return redirect(
                url_for("searchs.manage_search", search_id=search.id))
        else:
            flash_all_errors(form)

    form.submit.label.text = "Create"
    return render_template('search/create_search.html',
                           title="Create Search",
                           mode="Create",
                           form=form,
                           country_list=Country.list_all(),
                           town_list=Town.list_all(),
                           departement_list=Departement.list_all(),
                           region_list=Region.list_all())
Example #10
0
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)
Example #11
0
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())
Example #12
0
def update_searched_language(search_id):

    # handle connections problems
    handle_authentication(False)
    search = Search.query.filter_by(id=search_id).first()

    # authetication problem
    if current_user.id != search.user_id:
        flash("sorry this is not your search, you are not allowed", "danger")
        return redirect(url_for("main.edhunt"))

    form = SearchsForms.Languages()
    fields = extract_fields(form)

    if request.method == 'GET':
        # prefill all fields
        form.other_languages.data = search.other_languages
    else:
        if form.validate_on_submit():
            # update user attrs
            if form.other_languages.data:
                langs = form.other_languages.data
                langs = langs.capitalize().strip()\
                    .replace("-", " ").replace("  ", " ").replace("  ", " ")
                langs = ", ".join([i.strip() for i in langs.split(",")])
                form.other_languages.data = langs
            for field in fields:
                d = getattr(form, field).data
                if isinstance(d, list):
                    d = ", ".join(d)
                setattr(search, field, d)
            db.session.commit()
            flash("Search updated", "success")
            return redirect(
                url_for('searchs.manage_search', search_id=search.id))
        else:
            flash_all_errors(form)
    return render_template('search/update/update_searched_language.html',
                           title="Update Languages",
                           form=form,
                           search_id=search.id)
Example #13
0
def corporate_log():

    form = MainForms.Corporate()

    if request.method == 'GET':
        pass

    else:
        if form.validate_on_submit():
            flash("Super Merci!", "success")

            return render_template('main/corporate_data2.html',
                                   title="Corporate",
                                   text=MainText.home,
                                   corpo=MainText.corporate)
        else:
            flash_all_errors(form)

    return render_template('main/corporate_log.html',
                           title="Corporate",
                           text=MainText.corporate,
                           form=form)
Example #14
0
def contact():
    form = MainForms.Contact()
    fields = extract_fields(form)

    if request.method == 'GET':
        pass
    else:
        if form.validate_on_submit():
            contact = Contact()
            for field in fields:
                setattr(contact, field, getattr(form, field).data)
            db.session.add(contact)
            db.session.commit()

            flash("Message envoyé !", "success")
            return redirect(url_for("main.home"))
        else:
            flash_all_errors(form)

    return render_template('main/contact.html',
                           title="Contact",
                           form=form,
                           text=MainText.contact)
Example #15
0
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())
Example #16
0
def update_searched_job(search_id):

    # handle connections problems
    handle_authentication(False)
    search = Search.query.filter_by(id=search_id).first()
    # authetication problem
    if current_user.id != search.user_id:
        flash("sorry this is not your search, you are not allowed", "danger")
        return redirect(url_for("main.edhunt"))

    form = SearchsForms.Job()
    fields = extract_fields(form)
    if request.method == 'GET':
        # prefill all fields
        for field in fields:
            k = getattr(form, field)
            k.data = getattr(search, field)
    else:
        if form.validate_on_submit():
            # handle company (upper....)
            form.company.data = form.company.data.strip().upper()\
                .replace("-", " ").replace("  ", " ").replace("  ", " ")
            form.not_company.data = form.not_company.data.strip().upper()\
                .replace("-", " ").replace("  ", " ").replace("  ", " ")
            # if needed update Comany Table
            company_list = form.company.data.split(",")
            not_company_list = form.not_company.data.split(",")
            for comp_list in [company_list, not_company_list]:
                for _company in comp_list:
                    _company = _company.strip().upper().replace("-", " ")\
                        .replace("  ", " ").replace("  ", " ")
                    if _company not in Company.list_all():
                        db.session.add(Company(company=_company))
            if form.company.data:
                comps = form.company.data
                comps = comps.upper().strip()\
                    .replace("-", " ").replace("  ", " ").replace("  ", " ")
                comps = ", ".join([i.strip() for i in comps.split(",")])
                form.company.data = comps
            if form.not_company.data:
                comps = form.not_company.data
                comps = comps.upper().strip()\
                    .replace("-", " ").replace("  ", " ").replace("  ", " ")
                comps = ", ".join([i.strip() for i in comps.split(",")])
                form.not_company.data = comps
            if form.not_key_words.data:
                kwords = form.not_key_words.data
                kwords = kwords.lower().strip()\
                    .replace("-", " ").replace("  ", " ").replace("  ", " ")
                kwords = ", ".join([i.strip() for i in kwords.split(",")])
                form.not_key_words.data = kwords
            # update user attrs
            for field in fields:
                d = getattr(form, field).data
                if isinstance(d, list):
                    d = ", ".join(d)
                setattr(search, field, d)
            db.session.commit()
            flash("Search updated", "success")
            return redirect(
                url_for('searchs.manage_search', search_id=search.id))
        else:
            flash_all_errors(form)
    return render_template('search/update/update_searched_job.html',
                           title="Update Job",
                           form=form,
                           company_list=Company.list_all(),
                           search_id=search.id)
Example #17
0
def update_search(search_id):

    # handle connections problems
    handle_authentication(False)
    # form and fields
    form = SearchsForms.Update()
    search = Search.query.filter_by(id=search_id).first()
    # authetication problem
    if current_user.id != search.user_id:
        flash("sorry this is not your search, you are not allowed", "danger")
        return redirect(url_for("main.edhunt"))

    if request.method == 'GET':
        # prefill the form
        form.name.data = search.name
        form.mob.data = search.mob
        for feat in ['country', 'town', 'departement', 'region']:
            if getattr(search, feat) is None:
                setattr(search, feat, "")
            _data = [i.strip() for i in getattr(search, feat).split(",")]
            _data = _data + ([
                "",
            ] * (5 - len(_data)))
            [
                setattr(getattr(form, f"{feat}_{i+1}"), "data", j)
                for i, j in enumerate(_data)
            ]
        form.key_words.data = search.key_words
    else:
        if form.validate_on_submit():
            # if needed add the town to Town table
            for i in (1, 2, 3, 4, 5):
                town = getattr(form, f"town_{i}").data
                if town not in Town.list_all():
                    town = town.capitalize()\
                        .strip().replace("  ", " ").replace("  ", " ")
                    db.session.add(Town(town=town))
            # upadte user attrs
            search.name = form.name.data
            search.mob = form.mob.data
            for feat in ["country", "departement", "region", "town"]:
                _data = [
                    getattr(form, f"{feat}_{i}").data for i in [1, 2, 3, 4, 5]
                ]
                setattr(search, feat, ", ".join([i for i in _data if i]))
            form.key_words.data = form.key_words.data.strip().upper()\
                .replace("-", " ").replace("  ", " ").replace("  ", " ")
            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
            search.key_words = form.key_words.data
            db.session.commit()
            flash("search updated", "success")
            return redirect(
                url_for("searchs.manage_search", search_id=search.id))
        else:
            flash_all_errors(form)

    form.submit.label.text = "Update"
    return render_template('search/update/update_search.html',
                           title="Update Search",
                           mode="Update",
                           form=form,
                           country_list=Country.list_all(),
                           town_list=Town.list_all(),
                           region_list=Region.list_all(),
                           departement_list=Departement.list_all(),
                           search_id=search.id)