From c3348d3212952e202847b0dcf76edc5995d0ffac Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 11 Jul 2018 09:37:26 +0200 Subject: [PATCH] =?UTF-8?q?Make=20it=20possible=20to=20edit=20one=E2=80=99?= =?UTF-8?q?s=20profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …even though it’s only one field yet. --- calsocial/__init__.py | 16 ++++++++++++++++ calsocial/forms.py | 13 +++++++++++++ calsocial/templates/profile-edit.html | 17 +++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 calsocial/templates/profile-edit.html diff --git a/calsocial/__init__.py b/calsocial/__init__.py index 991c1c7..40e325e 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -399,5 +399,21 @@ class CalendarSocialApp(Flask): return render_template('first-steps.html', form=form) + @staticmethod + @route('/edit-profile', methods=['GET', 'POST']) + @login_required + def edit_profile(): + from .forms import ProfileForm + from .models import db + + form = ProfileForm(current_user.profile) + + if form.validate_on_submit(): + form.populate_obj(current_user.profile) + db.session.add(current_user.profile) + db.session.commit() + + return render_template('profile-edit.html', form=form) + app = CalendarSocialApp(__name__) diff --git a/calsocial/forms.py b/calsocial/forms.py index 06fdcfc..21f2343 100644 --- a/calsocial/forms.py +++ b/calsocial/forms.py @@ -335,3 +335,16 @@ class FirstStepsForm(FlaskForm): label=_('Your time zone'), validators=[DataRequired()], description=_('The start and end times of events will be displayed in this time zone.')) + + +class ProfileForm(FlaskForm): + """Form for editing a user profile + """ + + display_name = StringField(label=_('Display name'), validators=[DataRequired()]) + + def __init__(self, profile, *args, **kwargs): + kwargs.update({'display_name': profile.display_name}) + FlaskForm.__init__(self, *args, **kwargs) + + self.profile = profile diff --git a/calsocial/templates/profile-edit.html b/calsocial/templates/profile-edit.html new file mode 100644 index 0000000..f84d5c1 --- /dev/null +++ b/calsocial/templates/profile-edit.html @@ -0,0 +1,17 @@ +{% extends 'settings-base.html' %} + +{% block content %} +{{ super() }} +

{% trans %}Edit profile{% endtrans %}

+
+ {{ form.hidden_tag() }} + {{ form.errors }} + + {{ form.display_name.errors }} + {{ form.display_name.label }} + {{ form.display_name }} +
+ + +
+{% endblock content %}