def contact(): form = ContactForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: #msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**']) #msg.body = """ #From: %s <%s> #%s #""" % (form.name.data, form.email.data, form.message.data) #mail.send(msg) entry = Entry() form.populate_obj(entry) entry.token = os.urandom(24).encode('hex') #uuid.uuid4().hex) db.session.add(entry) try: db.session.commit() except exc.SQLAlchemyError: flash('All fields are required.') return render_template('contact.html', form=form, sqlerr="duplicate name/email") token = request.url_root + "search?token=" + entry.token print "token=", token return render_template('contact.html', success=True, qrcode_content=token, token=entry.token) elif request.method == 'GET': return render_template('contact.html', form=form)
def edit(id): contact = Contact.query.get(id) form = ContactForm(request.form, obj=contact) if form.validate_on_submit(): form.populate_obj(contact) db.session.commit() return 'ok' return render_template('_form.html', form=form)
def add(): form = ContactForm(request.form) if form.validate_on_submit(): contact = Contact() form.populate_obj(contact) db.session.add(contact) db.session.commit() return 'ok' return render_template('_form.html', form=form)
def edit(contact_id): # contact_id=4 data = contact.query.filter(contact.id == contact_id).first() if data: form = ContactForm(request.form, csrf_enabled=True, obj=data) if form.validate_on_submit(): form.populate_obj(data) db.session.commit() flash('contact updated successfully!') return render_template('success.html') return render_template('edit.html', form=form) else: return 'Error loading #{contact_id}'.format(contact_id=contact_id)
def edit_contact(uid=None): my_contact = Contact.query.filter_by(id=uid).first() if uid else None form = ContactForm(obj=my_contact) if form.validate_on_submit(): if not my_contact: my_contact = Contact() form.populate_obj(my_contact) db.session.add(my_contact) db.session.commit() flash('Saved successfully', 'success') if uid: return redirect(url_for('contacts')) return render_template('web/edit_contact.html', form=form)
def edit_contact(id): my_contact = Contact.query.filter_by(id=id).first() form = ContactForm(obj=my_contact) if form.validate_on_submit(): try: form.populate_obj(my_contact) database.session.add(my_contact) database.session.commit() flash('Save Successfully', 'success') return redirect(url_for('contacts')) except: database.session.rollback() flash('Error!', 'danger') return render_template('web/edit_contact.html', form=form)
def new_contact(): form = ContactForm() if form.validate_on_submit(): # create Contact Object my_contact = Contact() form.populate_obj(my_contact) database.session.add(my_contact) try: database.session.commit() flash("Contact created.", 'Success') return redirect(url_for('contacts')) except: database.session.rollback() flash('Error! ', 'danger') return render_template('web/new_contact.html', form=form)
def add_contact(): form = ContactForm(request.form) if request.method == 'POST' and form.validate(): #myContact = Contact(name=request.form.get('name'), # phone=request.form.get('phone'), # email=request.form.get('email')) myContact = Contact() form.populate_obj(myContact) db.session.add(myContact) try: db.session.commit() flash('Contacto creado satisfactoriamente', 'success') return redirect(url_for('contact_book')) except: db.session.rollback() flash('Error al generar contacto', 'danger') return render_template('add_contact.html')
def new_contact(): ''' Create new contact ''' form = ContactForm() if form.validate_on_submit(): my_contact = Contact() form.populate_obj(my_contact) db.session.add(my_contact) try: db.session.commit() # User info flash('Contact created correctly', 'success') return redirect(url_for('contacts')) except: db.session.rollback() flash('Error generating contact.', 'danger') return render_template('web/new_contact.html', form=form)
def edit_contact(uid): contact = Contact.query.get(uid) form = ContactForm(request.form) if request.method == 'POST' and form.validate(): myContact = Contact() form.populate_obj(myContact) contact.name = myContact.name contact.phone = myContact.phone contact.email = myContact.email try: db.session.add(contact) db.session.commit() flash('Contacto actualizado satisfactoriamente', 'success') #return redirect(url_for('contact_book')) except: db.session.rollback() flash('Error al generar contacto', 'danger') return render_template('edit_contact.html', contact=contact)
def edit_contact(id): ''' Edit contact :param id: Id from contact ''' my_contact = Contact.query.filter_by(id=id).first() form = ContactForm(obj=my_contact) if form.validate_on_submit(): try: # Update contact form.populate_obj(my_contact) db.session.add(my_contact) db.session.commit() # User info flash('Atualizado com sucesso.', 'success') except: db.session.rollback() flash('Erro ao atualizar.', 'danger') return render_template('web/edit_contact.html', form=form)
def new_contact(): ''' Create new contact ''' form = ContactForm() if form.validate_on_submit(): my_contact = Contact() form.populate_obj(my_contact) db.session.add(my_contact) try: db.session.commit() # User info flash('Funcionário adicionado com sucesso.', 'success') return redirect(url_for('contacts')) except Exception as error: print(error) db.session.rollback() flash('Erro ao adicionar o funcionário.', 'danger') return render_template('web/new_contact.html', form=form)
def new(): form = ContactForm(request.form, csrf_enabled=True) if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=form) else: form_contact = contact(request.form['name'], request.form['Gender'], request.form['Address'], request.form['email'], request.form['Age'], request.form['language']) form.populate_obj(form_contact) db.session.add(form_contact) db.session.commit() flash('Record was successfully added') return render_template('success.html') return render_template('success.html') elif request.method == 'GET': return render_template('contact.html', form=form)