Fixbug HTML and Fixbug new contact

This commit is contained in:
Andros Fenollosa 2017-05-16 22:00:20 +02:00
parent dee4e95d0d
commit e266dce5db
3 changed files with 8 additions and 14 deletions

12
app.py
View File

@ -27,11 +27,11 @@ def new_contact():
Create new contact
'''
form = ContactForm()
if form.validate_on_submit():
if form.validate_on_submit():
my_contact = Contact()
form.populate_obj(my_contact)
db.session.add(my_contact)
try:
my_contact = Contact()
form.populate_obj(my_contact)
db.session.add(my_contact)
db.session.commit()
# User info
flash('Contact created correctly', 'success')
@ -51,11 +51,11 @@ def edit_contact(id):
:param id: Id from contact
'''
my_contact = Contact.query.filter_by(id=id).first()
form = ContactForm(obj=my_contact)
form = ContactForm(obj=my_contact)
if form.validate_on_submit():
try:
# Update contact
form.populate_obj(my_contact)
form.populate_obj(my_contact)
db.session.add(my_contact)
db.session.commit()
# User info

View File

@ -18,11 +18,5 @@ class Contact(db.Model):
email = db.Column(db.String(200), nullable=True, unique=True)
phone = db.Column(db.String(20), nullable=True, unique=False)
def __init__(self, name, surname, email, phone):
self.name = name
self.surname = surname
self.email = email
self.phone = phone
def __repr__(self):
return '<Contacts %r>' % self.name

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="es">
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -18,7 +18,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Contactos</a>
<a class="navbar-brand" href="#">Contact Manager</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form action="{{ url_for('search') }}" method="get" class="navbar-form navbar-left">