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 %}