diff --git a/app.py b/app.py index 9ef1de2..c7fb3e6 100644 --- a/app.py +++ b/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() diff --git a/book.sqlite b/book.sqlite new file mode 100644 index 0000000..8cc4546 Binary files /dev/null and b/book.sqlite differ diff --git a/templates/web/edit_contact.html b/templates/web/edit_contact.html index 5842ef0..dd177fb 100644 --- a/templates/web/edit_contact.html +++ b/templates/web/edit_contact.html @@ -4,34 +4,17 @@

Edit contact

{{ form.csrf_token }} -
- {{ form.name.label }} - {{ form.name(class='form-control', value=my_contact.name) }} - {% for error in form.name.errors %} - {{ error }} - {% endfor %} -
-
- {{ form.surname.label }} - {{ form.surname(class='form-control', value=my_contact.surname) }} - {% for error in form.surname.errors %} - {{ error }} - {% endfor %} -
-
- {{ form.email.label }} - {{ form.email(class='form-control', value=my_contact.email) }} - {% for error in form.email.errors %} - {{ error }} - {% endfor %} -
-
- {{ form.phone.label }} - {{ form.phone(class='form-control', value=my_contact.phone) }} - {% for error in form.phone.errors %} - {{ error }} - {% endfor %} -
+ {% for field in form %} + {% if field.label.text != 'CSRF Token' %} +
+ {{ field.label }} + {{ field(class='form-control') }} + {% for error in field.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} + {% endfor %}
{% endblock %}