From ee42cbd32355669304c63cbffe2c9d758e373fc2 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 19 Jun 2024 11:17:34 +0200 Subject: views: make password optional in user/edit Add the option to leave the password fields empty in the form. When the passwords are not set the user keeps the old password configuration. Define a EditUserForm based on UserForm in forms/auth.py to remove the InputRequired validator in the password fields. Update the html template to make the password fields optional. --- ogcp/forms/auth.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ogcp/forms') diff --git a/ogcp/forms/auth.py b/ogcp/forms/auth.py index 72afe23..d85931b 100644 --- a/ogcp/forms/auth.py +++ b/ogcp/forms/auth.py @@ -9,7 +9,7 @@ from wtforms import ( Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, StringField, RadioField, PasswordField, SelectMultipleField, widgets ) -from wtforms.validators import InputRequired +from wtforms.validators import InputRequired, Optional from flask_wtf import FlaskForm from flask_babel import lazy_gettext as _l from flask_babel import _ @@ -55,6 +55,13 @@ class UserForm(FlaskForm): ) +class EditUserForm(UserForm): + def __init__(self, *args, **kwargs): + super(EditUserForm, self).__init__(*args, **kwargs) + self.pwd.validators = [Optional()] + self.pwd_confirm.validators = [Optional()] + + class DeleteUserForm(FlaskForm): username = HiddenField( validators=[InputRequired()] -- cgit v1.2.3-18-g5258