From d1310a67bfa6ca5e87f80e3658385eac889113cf Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 6 Apr 2022 13:50:08 +0200 Subject: [PATCH] add profile form --- ereuse_devicehub/forms.py | 36 ++++++- .../ereuse_devicehub/user_profile.html | 101 ++---------------- ereuse_devicehub/views.py | 4 +- 3 files changed, 47 insertions(+), 94 deletions(-) diff --git a/ereuse_devicehub/forms.py b/ereuse_devicehub/forms.py index d88c9cf1..dca1044c 100644 --- a/ereuse_devicehub/forms.py +++ b/ereuse_devicehub/forms.py @@ -1,9 +1,19 @@ from flask_wtf import FlaskForm from werkzeug.security import generate_password_hash -from wtforms import BooleanField, EmailField, PasswordField, validators +from wtforms import ( + BooleanField, + EmailField, + PasswordField, + SelectField, + StringField, + validators, +) +from ereuse_devicehub.enums import Country from ereuse_devicehub.resources.user.models import User +COUNTRY = [(x.name, x.value) for x in Country] + class LoginForm(FlaskForm): email = EmailField('Email Address', [validators.Length(min=6, max=35)]) @@ -59,3 +69,27 @@ class LoginForm(FlaskForm): self.form_errors.append(self.error_messages['inactive']) return user.is_active + + +class ProfileForm(FlaskForm): + name = StringField( + 'First name', + [validators.Length(min=2, max=35)], + render_kw={'class': "form-control"}, + ) + last_name = StringField( + 'Last name', + [validators.Length(min=2, max=35)], + render_kw={'class': "form-control"}, + ) + email = StringField( + 'Email Address', + [validators.Length(min=6, max=35)], + render_kw={'class': "form-control"}, + ) + telephone = StringField( + 'Phone', [validators.Length(min=6, max=35)], render_kw={'class': "form-control"} + ) + country = SelectField( + 'Country', choices=COUNTRY, default="es", render_kw={'class': "form-select"} + ) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/user_profile.html b/ereuse_devicehub/templates/ereuse_devicehub/user_profile.html index 326f3991..4b6468ba 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/user_profile.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/user_profile.html @@ -126,102 +126,19 @@
-
+ + {% for f in profile_form %} + {% if f == profile_form.csrf_token %} + {{ f }} + {% else %}
- +
- Profile -
- - -
+ {{ f }}
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- + {% endif %} + {% endfor %}
diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 1a2112a2..f6ed21f4 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -4,7 +4,7 @@ from flask.views import View from flask_login import current_user, login_required, login_user, logout_user from ereuse_devicehub import __version__ -from ereuse_devicehub.forms import LoginForm +from ereuse_devicehub.forms import LoginForm, ProfileForm from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.utils import is_safe_url @@ -50,11 +50,13 @@ class UserProfileView(View): template_name = 'ereuse_devicehub/user_profile.html' def dispatch_request(self): + form = ProfileForm() sessions = {s.created.strftime('%H:%M %d-%m-%Y') for s in current_user.sessions} context = { 'current_user': current_user, 'sessions': sessions, 'version': __version__, + 'profile_form': form, } return flask.render_template(self.template_name, **context)