Exemplo n.º 1
0
def contact():
    global current_page
    current_page = "contact"
    form = ContactForm()
    if form.is_submitted():
        try:
            oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{host}:{port}/{sid}'

            engine = create_engine(oracle_connection_string.format(
                username="******",
                password="******",
                sid="XE",
                host="localhost",
                port="1521",
                database="PROJECT",
            ),
                                   echo=True)

            Session = sessionmaker(bind=engine)
            session = Session()

            result = request.form
            adddata = customer(result['message'], result['customer_name'],
                               result['age'], result['email'],
                               result['tour_name'])
            session.add(adddata)
            session.commit()
            return render_template('contactsubmit.html', result=result)

        except:
            result = request.form
            return render_template('submitfail.html', result=result)
    return render_template('contact.html', form=form)
Exemplo n.º 2
0
def contact():
    cform = ContactForm()
    if cform.is_submitted():
        name = request.form['name']
        email = request.form['email']
        message = request.form['message']
        mycursor.execute(
            "INSERT INTO contact_table (name, email, message) VALUES (%s, %s, %s)",
            (name, email, message))
        mydb.commit()
        return redirect(url_for('index'))
    return render_template('contact.html', form=cform)
Exemplo n.º 3
0
def contacts_add():
    form = ContactForm()

    if form.is_submitted() and not form.validate():
        flash("Chyba při vstupu dat", category="error")

    if form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data

        id_obj = str(mongo.db.contacts.insert({'firstname': firstname, 'lastname': lastname}))

        flash("Kontakt byl přidán")
        return redirect(url_for('contact-view', id=id_obj))

    return render_template('contact-form.html', form=form)
Exemplo n.º 4
0
def contact_edit(id):
    id_obj = ObjectId(id)
    contact = mongo.db.contacts.find_one({'_id': id_obj}) or abort(404)
    form = ContactForm()

    if form.is_submitted() and not form.validate():
        flash("Chyba při vstupu dat", category="error")

    if form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data

        print(firstname, lastname)

        id_obj = mongo.db.contacts.update_one({'_id': id_obj}, {"$set": {'firstname': firstname, 'lastname': lastname}})

        flash("Kontakt byl editován")
        return redirect(url_for('contact-view', id=id))


    form.firstname.data = contact['firstname']
    form.lastname.data = contact['lastname']

    return render_template('contact-edit.html', form=form)