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

View File

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

View File

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