Optimize generate forms edit contact
This commit is contained in:
parent
ce763d6493
commit
af745f5f3f
12
app.py
12
app.py
@ -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()
|
||||
|
BIN
book.sqlite
Normal file
BIN
book.sqlite
Normal file
Binary file not shown.
@ -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 %}
|
||||
{% 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>
|
||||
<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>
|
||||
{% endif %}
|
||||
{% 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">
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user