- {{ wtf.render_field(edit_public_profile_information_form.avatar, accept='image/jpeg, image/png, image/gif', placeholder='Choose an image file', id='avatar-upload', data_action='disable') }}
+ {{ wtf.render_field(edit_public_profile_information_form.avatar, accept='image/jpeg, image/png, image/gif', placeholder='Choose an image file', id='avatar-upload') }}
diff --git a/app/templates/users/profile.html.j2 b/app/templates/users/profile.html.j2
index b8c0ad19..574fd6c9 100644
--- a/app/templates/users/profile.html.j2
+++ b/app/templates/users/profile.html.j2
@@ -91,7 +91,7 @@
-
+ {#
{% endblock page_content %}
diff --git a/app/users/forms.py b/app/users/forms.py
index 50594519..5fd5d81e 100644
--- a/app/users/forms.py
+++ b/app/users/forms.py
@@ -8,23 +8,24 @@ from wtforms import (
ValidationError
)
from wtforms.validators import (
- InputRequired,
+ DataRequired,
Email,
Length,
Regexp
)
from app.models import User
from app.auth import USERNAME_REGEX
+from app.wtf_validators import FileSizeLimit
class EditProfileSettingsForm(FlaskForm):
email = StringField(
'E-Mail',
- validators=[InputRequired(), Length(max=254), Email()]
+ validators=[DataRequired(), Length(max=254), Email()]
)
username = StringField(
'Username',
validators=[
- InputRequired(),
+ DataRequired(),
Length(max=64),
Regexp(
USERNAME_REGEX,
@@ -53,7 +54,8 @@ class EditProfileSettingsForm(FlaskForm):
class EditPublicProfileInformationForm(FlaskForm):
avatar = FileField(
- 'Image File'
+ 'Image File',
+ [FileSizeLimit(max_size_in_mb=2)]
)
full_name = StringField(
'Full name',
diff --git a/app/wtf_validators.py b/app/wtf_validators.py
new file mode 100644
index 00000000..326ef7e7
--- /dev/null
+++ b/app/wtf_validators.py
@@ -0,0 +1,9 @@
+from wtforms.validators import ValidationError
+
+def FileSizeLimit(max_size_in_mb):
+ max_bytes = max_size_in_mb*1024*1024
+ def file_length_check(form, field):
+ if len(field.data.read()) > max_bytes:
+ raise ValidationError(f"File size must be less than {max_size_in_mb}MB")
+ field.data.seek(0)
+ return file_length_check
Social
Find public corpora