Merge branch 'master' into feature/css_fix_and_dissmissable_alerts

This commit is contained in:
Kyle Roux 2017-05-16 11:06:21 -07:00
commit 060fe68c71
4 changed files with 24 additions and 42 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
book.sqlite

12
app.py
View File

@ -55,8 +55,13 @@ def edit_contact(id):
:param id: Id from contact
'''
form = ContactForm()
my_contact = Contact.query.filter_by(id=id).first()
form = ContactForm(
name=my_contact.name,
surname=my_contact.surname,
email=my_contact.email,
phone=my_contact.phone
)
if form.validate_on_submit():
# Get form
name = form.name.data
@ -79,8 +84,7 @@ def edit_contact(id):
flash('Error update contact.', 'danger')
return render_template(
'web/edit_contact.html',
form=form,
my_contact=my_contact)
form=form)
@app.route("/contacts")
@ -108,8 +112,6 @@ def search():
def contacts_delete():
'''
Delete contact
:param id: Id from contact
'''
try:
mi_contacto = Contact.query.filter_by(id=request.form['id']).first()

View File

@ -21,15 +21,11 @@
<td>{{ contact.phone }}</td>
<td class="text-right">
<div class="row">
<div class="col-xs-6">
<a class="btn btn-primary" href="{{ url_for('edit_contact', id=contact.id) }}">Edit</a>
</div>
<div class="col-xs-6">
<form action="{{ url_for('contacts_delete') }}" method="post">
<input type="hidden" name="id" value="{{ contact.id }}">
<input type="submit" class="btn btn-danger" data-toggle="confirmation" {# data-title="¿Estas seguro?" #} value="Delete">
</form>
</div>
<form action="{{ url_for('contacts_delete') }}" method="post" class="pull-right">
<input type="hidden" name="id" value="{{ contact.id }}">
<input type="submit" class="btn btn-danger" data-toggle="confirmation" {# data-title="¿Estas seguro?" #} value="Delete">
</form>
<a class="btn btn-primary pull-right" href="{{ url_for('edit_contact', id=contact.id) }}">Edit</a>
</div>
</td>
</tr>

View File

@ -4,34 +4,17 @@
<h1>Edit contact</h1>
<form method="post">
{{ form.csrf_token }}
<div class="form-group{%if form.name.errors %} has-error{% endif %}">
{{ form.name.label }}
{{ form.name(class='form-control', value=my_contact.name) }}
{% for error in form.name.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
</div>
<div class="form-group{%if form.surname.errors %} has-error{% endif %}">
{{ form.surname.label }}
{{ form.surname(class='form-control', value=my_contact.surname) }}
{% for error in form.surname.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
</div>
<div class="form-group{%if form.email.errors %} has-error{% endif %}">
{{ form.email.label }}
{{ form.email(class='form-control', value=my_contact.email) }}
{% for error in form.email.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
</div>
<div class="form-group{%if form.phone.errors %} has-error{% endif %}">
{{ form.phone.label }}
{{ form.phone(class='form-control', value=my_contact.phone) }}
{% for error in form.phone.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
</div>
{% for field in form %}
{% if field.label.text != 'CSRF Token' %}
<div class="form-group{%if field.errors %} has-error{% endif %}">
{{ field.label }}
{{ field(class='form-control') }}
{% for error in field.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
</div>
{% endif %}
{% endfor %}
<input type="submit" class="btn btn-success" value="Save">
</form>
{% endblock %}