Make it possible to edit one’s profile

…even though it’s only one field yet.
This commit is contained in:
Gergely Polonkai 2018-07-11 09:37:26 +02:00
parent 1a69928241
commit c3348d3212
3 changed files with 46 additions and 0 deletions

View File

@ -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__)

View File

@ -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

View File

@ -0,0 +1,17 @@
{% extends 'settings-base.html' %}
{% block content %}
{{ super() }}
<h2>{% trans %}Edit profile{% endtrans %}</h2>
<form method="post">
{{ form.hidden_tag() }}
{{ form.errors }}
{{ form.display_name.errors }}
{{ form.display_name.label }}
{{ form.display_name }}
<br>
<button type="submit">{% trans %}Save{% endtrans %}</button>
</form>
{% endblock content %}