mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-11 08:30:41 +00:00
Fix problems with new forms
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from flask_login import current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField, FileRequired
|
||||
from wtforms import (
|
||||
PasswordField,
|
||||
@ -15,11 +16,11 @@ from wtforms.validators import (
|
||||
Length,
|
||||
Regexp
|
||||
)
|
||||
from app.forms import NopaqueForm, LimitFileSize
|
||||
from app.models import User, UserSettingJobStatusMailNotificationLevel
|
||||
from app.wtforms.validators import FileSize
|
||||
|
||||
|
||||
class UpdateAccountInformationForm(NopaqueForm):
|
||||
class UpdateAccountInformationForm(FlaskForm):
|
||||
email = StringField(
|
||||
'E-Mail',
|
||||
validators=[DataRequired(), Length(max=254), Email()]
|
||||
@ -43,6 +44,8 @@ class UpdateAccountInformationForm(NopaqueForm):
|
||||
def __init__(self, *args, user=current_user, **kwargs):
|
||||
if 'data' not in kwargs:
|
||||
kwargs['data'] = user.to_json_serializeable()
|
||||
if 'prefix' not in kwargs:
|
||||
kwargs['prefix'] = 'update-account-information-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
self.user = user
|
||||
|
||||
@ -57,7 +60,7 @@ class UpdateAccountInformationForm(NopaqueForm):
|
||||
raise ValidationError('Username already in use')
|
||||
|
||||
|
||||
class UpdateProfileInformationForm(NopaqueForm):
|
||||
class UpdateProfileInformationForm(FlaskForm):
|
||||
full_name = StringField(
|
||||
'Full name',
|
||||
validators=[Length(max=128)]
|
||||
@ -91,11 +94,13 @@ class UpdateProfileInformationForm(NopaqueForm):
|
||||
def __init__(self, *args, user=current_user, **kwargs):
|
||||
if 'data' not in kwargs:
|
||||
kwargs['data'] = user.to_json_serializeable()
|
||||
if 'prefix' not in kwargs:
|
||||
kwargs['prefix'] = 'update-profile-information-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class UpdateAvatarForm(NopaqueForm):
|
||||
avatar = FileField('File', validators=[FileRequired(), LimitFileSize(2)])
|
||||
class UpdateAvatarForm(FlaskForm):
|
||||
avatar = FileField('File', validators=[FileRequired(), FileSize(2)])
|
||||
submit = SubmitField()
|
||||
|
||||
def validate_avatar(self, field):
|
||||
@ -103,7 +108,13 @@ class UpdateAvatarForm(NopaqueForm):
|
||||
if field.data.mimetype not in valid_mimetypes:
|
||||
raise ValidationError('JPEG and PNG files only!')
|
||||
|
||||
class UpdatePasswordForm(NopaqueForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'prefix' not in kwargs:
|
||||
kwargs['prefix'] = 'update-avatar-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class UpdatePasswordForm(FlaskForm):
|
||||
password = PasswordField('Old password', validators=[DataRequired()])
|
||||
new_password = PasswordField(
|
||||
'New password',
|
||||
@ -122,6 +133,8 @@ class UpdatePasswordForm(NopaqueForm):
|
||||
submit = SubmitField()
|
||||
|
||||
def __init__(self, *args, user=current_user, **kwargs):
|
||||
if 'prefix' not in kwargs:
|
||||
kwargs['prefix'] = 'update-password-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
self.user = user
|
||||
|
||||
@ -130,7 +143,7 @@ class UpdatePasswordForm(NopaqueForm):
|
||||
raise ValidationError('Invalid password')
|
||||
|
||||
|
||||
class UpdateNotificationsForm(NopaqueForm):
|
||||
class UpdateNotificationsForm(FlaskForm):
|
||||
job_status_mail_notification_level = SelectField(
|
||||
'Job status mail notification level',
|
||||
choices=[
|
||||
@ -144,4 +157,6 @@ class UpdateNotificationsForm(NopaqueForm):
|
||||
def __init__(self, *args, user=current_user, **kwargs):
|
||||
if 'data' not in kwargs:
|
||||
kwargs['data'] = user.to_json_serializeable()
|
||||
if 'prefix' not in kwargs:
|
||||
kwargs['prefix'] = 'update-notifications-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
|
Reference in New Issue
Block a user