From 3e5d8ee4d53013fff164cf571588a31a1b866e50 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 25 Jul 2018 08:35:44 +0200 Subject: [PATCH] =?UTF-8?q?Make=20it=20possible=20to=20set=20one=E2=80=99s?= =?UTF-8?q?=20avatar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only built-in avatars are supported yet. --- calsocial/forms.py | 14 +++++++++++--- calsocial/templates/account/profile-edit.html | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/calsocial/forms.py b/calsocial/forms.py index e066d7a..4d2ed3a 100644 --- a/calsocial/forms.py +++ b/calsocial/forms.py @@ -23,7 +23,7 @@ from flask_babelex import lazy_gettext as _ from flask_security.forms import LoginForm as BaseLoginForm from flask_wtf import FlaskForm 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.validators import DataRequired, Email, StopValidation, ValidationError from wtforms.widgets import TextArea @@ -394,11 +394,19 @@ class ProfileForm(FlaskForm): """ display_name = StringField(label=_('Display name'), validators=[DataRequired()]) + builtin_avatar = RadioField(label=_('Use a built-in avatar')) locked = BooleanField(label=_('Lock profile')) def __init__(self, profile, *args, **kwargs): - kwargs.update({'display_name': profile.display_name}) - kwargs.update({'locked': profile.locked}) + from flask import current_app + + kwargs.update( + { + 'display_name': profile.display_name, + 'locked': profile.locked, + 'builtin_avatar': profile.builtin_avatar, + }) FlaskForm.__init__(self, *args, **kwargs) + self.builtin_avatar.choices = [(name, name) for name in current_app.config['BUILTIN_AVATARS']] self.profile = profile diff --git a/calsocial/templates/account/profile-edit.html b/calsocial/templates/account/profile-edit.html index ecb38a1..650a4d9 100644 --- a/calsocial/templates/account/profile-edit.html +++ b/calsocial/templates/account/profile-edit.html @@ -13,6 +13,7 @@
{% endif %} + {{ field(form.builtin_avatar) }} {{ field(form.display_name) }} {{ field(form.locked, inline=true) }}