Esempio n. 1
0
def contact_create():
    form = ContactUpdateForm()
    if form.validate_on_submit():
        contact_db = model.Contact(
            user_key=auth.current_user_key(),
            name=form.name.data,
            email=form.email.data,
            phone=form.phone.data,
            address=form.address.data,
        )
        contact_db.put()
        return flask.redirect(flask.url_for('welcome'))
    return flask.render_template(
        'contact_update.html',
        html_class='contact-create',
        title='Create Contact',
        form=form,
    )
Esempio n. 2
0
def contact_create():
  form = ContactUpdateForm()
  if form.validate_on_submit():
    contact_db = model.Contact(
        user_key=auth.current_user_key(),
        name=form.name.data,
        email=form.email.data,
        phone=form.phone.data,
        address=form.address.data,
      )
    contact_db.put()
    flask.flash('New contact was successfully created!', category='success')
    return flask.redirect(flask.url_for('contact_list', order='-created'))
  return flask.render_template(
      'contact_update.html',
      html_class='contact-create',
      title='Create Contact',
      form=form,
    )
Esempio n. 3
0
def add_contacts():
    form = forms.ContactForm()
    if form.validate_on_submit():
        number_query = model.session.query(model.Contact).filter(
            and_(model.Contact.user_id == current_user.id,
                 model.Contact.phone_number == form.phone_number.data)).all()
        if not number_query:
            contact = model.Contact(id=None,
                                    user_id=current_user.id,
                                    first_name=form.first_name.data,
                                    last_name=form.last_name.data,
                                    phone_number=form.phone_number.data,
                                    last_called=None,
                                    last_confirmation=None)
            model.session.add(contact)
            model.session.commit()
            return redirect("/contacts")
        else:
            flash('Phone number is attached to another contact.')
            return redirect('/add_contacts')
    else:
        return render_template("add_contacts.html", form=form)