def register_application():
    application_form = ApplicationForm(meta={'csrf': False})

    if application_form.validate_on_submit():
        car_brand = request.form['car_brand']
        car_model = request.form['car_model']
        name = request.form['name']
        last_name = request.form['last_name']
        email = request.form['email']
        tel = request.form['tel']

        try:
            application = Application(name=name, last_name=last_name, email=email, tel=tel, car_brand_id=car_brand,
                                      car_model_id=car_model)
            db.session.add(application)
            db.session.commit()

            # !!!
            # Uncomment it if you want to use Mail
            # !!!

            # track_number = application.unique_track_number
            # send_application_registered_msg(name, email, track_number)

            return jsonify({'success': 'Ваша заявка была успешно подана!'})
        except Exception as e:
            return jsonify({'errors': f'Что-то пошло не так, попробуйте снова! {e}'})

    return jsonify({'errors': application_form.errors})
Esempio n. 2
0
def setting_application():
    # 表格信息区
    applications = db.engine.execute(SQL['APPLICATION_INFO'])
    application_choices = [(p.id, p.application_name) for p in Application.query.order_by('id')]
    user_choices = [(p.id, p.user_name) for p in User.query.filter(User.enable == 1).order_by('id')]
    status_choices = APPLICATION_STATUS
    # 增加项目区
    add_form = ApplicationForm()
    add_form.product_manger_id.choices = user_choices
    if add_form.validate_on_submit():
        if g.user.role == 0:
            try:
                new_application = Application(add_form.application_name.data, add_form.product_manger_id.data,
                                              add_form.current_version.data, add_form.status.data)
                db.session.add(new_application)
                db.session.commit()
                log('application', '增加系统', new_application.id, new_application.application_name, '成功')
                flash("系统添加成功!")
            except Exception, e:
                flash("无法添加系统!")
                print Exception, e
                return render_template('setting-application.html', data=applications, user_choices=user_choices,
                                       status_choices=status_choices, add_form=add_form,
                                       application_choices=application_choices, atr='show')
        else:
            flash("无权限操作!")
Esempio n. 3
0
def return_loan_application():
    form = ApplicationForm()
    message = ''
    if form.validate_on_submit():
        age = form.age.data
        occupation = form.occupation.data

        credit = form.grade.data
        grade = convert_credit_grade(credit)
        Years_At_present_Employment = form.Years_At_present_Employment.data

        expenses = form.expenses.data
        income = form.income.data
        dti = round((expenses / (income / 12) * 100), 2)

        Delinquency = convert_to_binary(form.Delinquency.data)
        Collections = convert_to_binary(form.Collections.data)
        Derogatory = convert_to_binary(form.Derogatory.data)
        Housing = form.Housing.data

        application_data = [[grade, dti, Delinquency, Collections, Derogatory]]

        probabs_result = tfidf_model.predict_proba(application_data)

        default_chance = probabs_result[1][0][1]

        print('Chance of default: {}'.format(default_chance * 100))

        if default_chance > .3:
            message = 'However you have been rejected :('
            approval = 'rejected'
        else:
            message = 'You have been accepted! :)'
            approval = 'accepted'

        insert_query = "INSERT INTO loan_history VALUES(DEFAULT, {}, '{}', {}, '{}', '{}', '{}', '{}')".format(
            age, occupation, Years_At_present_Employment, income, Housing,
            credit, approval)

        # print(insert_query)

        cur.execute(insert_query)
        conn.commit()

        return render_template('application_complete.html', message=message)

    return render_template('loan_application.html', form=form)
Esempio n. 4
0
def save_applications(nickname, jobkey):
    print "====== got into save_applications jobkey: ", jobkey
    set_upload_dir(nickname)
    form = ApplicationForm()

    # get the job data from the database or server
    job_data = Position.query.filter_by(jobkey=jobkey).first();
    if job_data is None:
        getJob = ProcessJobSearch()
        job = getJob.search_by_jobkeys(jobkey)
        job_data = job[0]
        print "title: %s, jobkey: %s, company: %s" % (job_data['jobtitle'],
                                                      job_data['jobkey'], job_data['company'])
    if request.method == 'POST' and form.validate_on_submit():
        position =  Position.query.filter_by(jobkey=jobkey).first();
        if position is None:
            print " ---- inserting into position table ----"
            position = insert_into_position_table(job_data)
        apply_date = form.apply_date.data
        dt = datetime.strptime(apply_date, "%m/%d/%Y" )
        resume = form.resume_version.data
        cv = form.cv_version.data
        username = form.username_on_website.data
        password = form.password_on_website.data

        #insert into Application table
        user = User.query.filter_by(nickname=nickname).first()
        if user is not None:
            application = Application.query.filter_by(id=user.id, jobkey=position.jobkey).first()
            if application is None:

                print("commit to application table")
                application = Application(id=user.id, jobkey=position.jobkey,
                                          apply_date=dt, resume=resume, cv=cv)
                db.session.add(application)
                db.session.commit()
        else:
            print(" We couldn't save the position.")
        return redirect(url_for('list_applications', nickname=nickname))

    print "documents available: ", os.listdir(g.user.upload_dir), " path is: ", g.user.upload_dir
    documents = os.listdir(g.user.upload_dir)
    return render_template('save_applications.html',
                           job=job_data,
                           user=g.user, form=form,
                           documents=documents)
Esempio n. 5
0
	def apply():
		form = ApplicationForm()
		if form.validate_on_submit():
			file = request.files['resume']
			if file and allowed_file(file.filename):
				filename = secure_filename(file.filename)
				file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
				new_applicant = Application()
				form.populate_obj(new_applicant)
				new_applicant.resume = filename
				db.session.add(new_applicant)
				db.session.commit()
				return "Thanks for applying!"
			else:
				flash("Invalid file extension")
				return render_template('application.html', form=form)		
		return render_template('application.html', form=form)
Esempio n. 6
0
    def index():
        form = ApplicationForm()

        if form.validate_on_submit():
            if form.squirrel.data:
                # ANTI SPAM YO
                app.logger.info('SECRET SQUIRREL')
                return redirect(url_for('index'))

            form_data = "name: {}\nemail: {}\nphone: {}\n\n".format(
                form.name.data, form.email.data, form.phone.data)
            app.logger.info(form_data)

            # send the email
            email.send(form_data)

            flash(app.config['THANKS_FLASH'])

            return redirect(url_for('index'))

        return render_template('index.jade', form=form)
Esempio n. 7
0
def application_edit(app_id):

    from forms import ApplicationForm

    ac = Application.query.get_u_or_404(app_id)
    servers = Server.query.all()
    form = ApplicationForm(
        formdata=request.form, 
        obj=ac)

    if form.validate_on_submit():
        form.servers.data = [ 
            Server.query.get_or_404(x) for x in form.servers.data]
        form.populate_obj(ac)

        db.session.commit()
        return redirect(url_for(".application"))

    return render_template("app_edit.html",
        form=form,
        servers=servers,
        ac=ac)
Esempio n. 8
0
def apply():
    if current_user.is_authenticated:
        if current_user.type == 'admin':
            return redirect(url_for('main.index'))
        return redirect(url_for('student.studentIndex'))
    form = ApplicationForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user is not None:
                flash('There is already an account with that email.',
                      'warning')
                return redirect(url_for('student.apply'))
            stu = Student.query.filter_by(email=form.email.data).first()
            if stu is not None:
                flash('There is already a student with that email.', 'warning')
                return redirect(url_for('student.apply'))
            applicant = Applicant.query.filter_by(
                email=form.email.data).first()
            if applicant is not None:
                flash('You have already applied with that email.', 'warning')
                return redirect(url_for('student.apply'))
            if form.document.data:
                document = save_doc(form.document.data)
            student = Applicant(name=form.name.data,
                                birthday=form.birthday.data,
                                phone=form.phone.data,
                                address=form.address.data,
                                email=form.email.data,
                                status=False,
                                city=form.city.data,
                                country=form.country.data,
                                program=form.program.data,
                                document=document)
            db.session.add(student)
            db.session.commit()
            flash('You application has been received!', 'success')
            return redirect(url_for('student.studentlogin'))
    return render_template('apply.html', form=form)
Esempio n. 9
0
    def index():
        form = ApplicationForm()

        if form.validate_on_submit():
            if form.squirrel.data:
                # ANTI SPAM YO
                app.logger.info('SECRET SQUIRREL')
                return redirect(url_for('index'))

            form_data = "name: {}\nemail: {}\nphone: {}\n\n".format(
                    form.name.data,
                    form.email.data,
                    form.phone.data
                    )
            app.logger.info(form_data)

            # send the email
            email.send(form_data)

            flash(app.config['THANKS_FLASH'])

            return redirect(url_for('index'))

        return render_template('index.jade', form=form)
Esempio n. 10
0
def application_add():

    from forms import ApplicationForm

    servers = Server.query.all()
    form = ApplicationForm(request.form)
    iservers = request.form.getlist('servers')
    iservers = Server.query.filter(
        Server.id.in_(iservers)).all()

    if form.validate_on_submit():

        s = Application()
        form.servers.data = [ 
            Server.query.get_or_404(x) for x in form.servers.data]
        form.populate_obj(s)
        db.session.add(s)
        db.session.commit()
        return redirect(url_for(".application"))

    return render_template("app_add.html",
        form=form,
        servers=servers,
        iservers=iservers)