Merge branch 'master' into feature/made_base_form_class
This commit is contained in:
commit
68d16991cd
16
app.py
16
app.py
@ -4,7 +4,8 @@ from forms import ContactForm
|
||||
|
||||
# Flask
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'my secret'
|
||||
app.config['SECRET_KEY'] = 'my secret'
|
||||
app.config['DEBUG'] = True
|
||||
|
||||
# Database
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///book.sqlite'
|
||||
@ -27,11 +28,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 +52,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
|
||||
@ -107,5 +108,4 @@ def contacts_delete():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.debug = True
|
||||
app.run()
|
||||
|
@ -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
|
||||
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user