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

View File

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

View File

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