def create(request): print request.POST print request.POST['name'] print request.POST['breed'] contacts = Contacts(name=request.POST['name'], breed=request.POST['breed']) contacts.save() return redirect('/')
def createContact(): first = input("First Name: ") last = input("Last Name: ") number = input("Phone Number: ") email = input("Email: ") Contacts.create(first_name=first, last_name=last, number=number, email=email)
def post(self): contacts = json.loads(self.request.get("contacts",'{}')) email = contacts['__email__online__sms'][0].lower() del contacts['__email__online__sms'] q = Contacts.query(Contacts.email == email) c = q.get() if c:c.data = contacts else:c=Contacts(email=email, data=contacts) c.put() self.response.out.write(json.dumps({}))
def deleteContact(): deleteName = input("Type the name of the contact you wish to delete: ") deleteContact = Contacts.get(Contacts.first_name == deleteName) print(deleteContact.first_name, deleteContact.last_name, deleteContact.number, deleteContact.email) deleteContact.delete_instance() print("deleted") all = Contacts.select() for entry in all: print(entry.first_name, entry.last_name, entry.number, entry.email)
def contact(): form = ContactForm(request.form) if request.method == 'POST' and form.validate(): name = form.data['name'] email = form.data['email'] message = form.data['message'] contact = Contacts(name=name, email=email, comment=message) contact.save() send_email(name, email, message) time.sleep(5) return redirect('/') context = {'form': form} content = render_template('contact.html', **context) return content
def contact_add(): """ Helper page to add contacts while on Heroku. """ if request.method == "POST": try: print('Inside try') name = request.form['inputn'] phone_no = request.form['inputp'] print(name, phone_no) row = Contacts(name=name, phone_no=phone_no) db.session.add(row) print('Added result to session') db.session.commit() print('DB Addition Success') except Exception as e: db.session.rollback() print("Unable to add item to database.") print(e) finally: db.session.close() return render_template('contactadd.html')
def add_contact(): add_contact = forms.SignupForm(request.form) if request.method == 'POST': contacts = Contacts(id, fullname=add_contact.fullname.data, phone=add_contact.phone.data, email=add_contact.email.data) db.session.add(contacts) db.session.commit() flash('Contacto agregado exitosamente') return redirect(url_for('index'))
def updateContact(): updateName = input( "Type the first name of the contact you would like to update: ") person = Contacts.get(Contacts.first_name == updateName) findField = input( "Enter the number of the field you would like to update:\n" "1. First Name\n" "2. Last Name\n" "3. Phone Number\n" "4. Email Address: ") if findField == "1": print(f"First Name:\n {person.first_name}") elif findField == "2": print(f"Last Name:\n {person.first_name}: {person.last_name}") elif findField == "3": print(f"Phone Number:\n {person.first_name}: {person.number}: ") elif findField == "4": print(f"Email Address:\n {person.first_name}: {person.email}") else: print("Select Again") newData = input("Please enter the new text of the field: ") print(newData) last = Contacts.get(Contacts.last_name == person.last_name) num = Contacts.get(Contacts.number == person.number) mail = Contacts.get(Contacts.email == person.email) if findField == "1": person = Contacts.get(Contacts.first_name == updateName) person.first_name = newData person.save() elif findField == "2": last = Contacts.get(Contacts.last_name == person.last_name) last.last_name = newData last.save() # print(person.last_name, last.last_name, "three") elif findField == "3": num = Contacts.get(Contacts.number == person.number) num.number = newData num.save() elif findField == "4": mail = Contacts.get(Contacts.email == person.email) mail.email = newData mail.save() print(person.first_name, last.last_name, num.number, mail.email)
def contact_us(): if(request.method=='POST'): name = request.form.get('name') email = request.form.get('email') phone = request.form.get('phone') message = request.form.get('message') entry = Contacts(name=name, phone_num = phone, msg = message, date= datetime.now(),email = email ) db.session.add(entry) db.session.commit() flash('Data Saved Successfully') mail.send_message('New message from ' + name, sender=email, recipients = [params['gmail-user']], body = message + "\n" + phone ) return render_template('contactUs.html', params=params)
def new_contact(): ''' Create new contact ''' form = ContactForm() if request.method == 'POST' and form.validate_on_submit(): # Get form name = request.form['name'] surname = request.form['surname'] email = request.form['email'] phone = request.form['phone'] # Save in database try: my_contact = Contacts(name, surname, email, phone) db.session.add(my_contact) 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 addcontact(): user_reference = request.args.get('user_ref') phone = request.args.get('phone') contact = Contacts(user_reference, phone) return jsonify(contact=contact.insert_into_db())
"phone_number": "72780272317", "date_birth": "2011-01-18", "histories": [ ("2019-01-08 22:17:54"), ("2019-11-06 12:17:54"), ] }] if os.path.exists('contacts.db'): os.remove('contacts.db') db.create_all() for contacts in CONTACTS_LIST: con = Contacts(first_name=contacts.get('first_name'), last_name=contacts.get('last_name'), phone_number=contacts.get('phone_number'), date_birth=contacts.get('date_birth')) for his in contacts.get('histories'): created_at = his con.histories.append( History( created_at=datetime.strptime(created_at, "%Y-%m-%d %H:%M:%S"))) db.session.add(con) db.session.commit()
def get(self): user = users.get_current_user() email = user.email().lower() res = Contacts.query(Contacts.email==email).get().data self.response.out.write(json.dumps(res))
from models import db, Contacts from faker import Factory fake = Factory.create() # Spanish #fake = Factory.create('es_ES') # Reload tables db.drop_all() db.create_all() # Make 100 fake contacts for num in range(100): fullname = fake.name().split() name = fullname[0] surname = ' '.join(fullname[1:]) email = fake.email() phone = fake.phone_number() # Save in database mi_contacto = Contacts(name, surname, email, phone) db.session.add(mi_contacto) db.session.commit()
def findAll(): all = Contacts.select() for entry in all: print(entry.first_name, entry.last_name, entry.number, entry.email)
def findName(): person = Contacts.get(Contacts.first_name == menu) print(person.first_name, person.last_name, person.number, person.email)