Make it possible to set one’s avatar

Only built-in avatars are supported yet.
This commit is contained in:
Gergely Polonkai 2018-07-25 08:35:44 +02:00
parent c0c38ccb52
commit 3e5d8ee4d5
2 changed files with 12 additions and 3 deletions

View File

@ -23,7 +23,7 @@ from flask_babelex import lazy_gettext as _
from flask_security.forms import LoginForm as BaseLoginForm from flask_security.forms import LoginForm as BaseLoginForm
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
import pytz import pytz
from wtforms import BooleanField, PasswordField, SelectField, StringField from wtforms import BooleanField, PasswordField, SelectField, StringField, RadioField
from wtforms.ext.dateutil.fields import DateTimeField from wtforms.ext.dateutil.fields import DateTimeField
from wtforms.validators import DataRequired, Email, StopValidation, ValidationError from wtforms.validators import DataRequired, Email, StopValidation, ValidationError
from wtforms.widgets import TextArea from wtforms.widgets import TextArea
@ -394,11 +394,19 @@ class ProfileForm(FlaskForm):
""" """
display_name = StringField(label=_('Display name'), validators=[DataRequired()]) display_name = StringField(label=_('Display name'), validators=[DataRequired()])
builtin_avatar = RadioField(label=_('Use a built-in avatar'))
locked = BooleanField(label=_('Lock profile')) locked = BooleanField(label=_('Lock profile'))
def __init__(self, profile, *args, **kwargs): def __init__(self, profile, *args, **kwargs):
kwargs.update({'display_name': profile.display_name}) from flask import current_app
kwargs.update({'locked': profile.locked})
kwargs.update(
{
'display_name': profile.display_name,
'locked': profile.locked,
'builtin_avatar': profile.builtin_avatar,
})
FlaskForm.__init__(self, *args, **kwargs) FlaskForm.__init__(self, *args, **kwargs)
self.builtin_avatar.choices = [(name, name) for name in current_app.config['BUILTIN_AVATARS']]
self.profile = profile self.profile = profile

View File

@ -13,6 +13,7 @@
<br> <br>
{% endif %} {% endif %}
{{ field(form.builtin_avatar) }}
{{ field(form.display_name) }} {{ field(form.display_name) }}
{{ field(form.locked, inline=true) }} {{ field(form.locked, inline=true) }}