diff --git a/calsocial/__init__.py b/calsocial/__init__.py index 693a875..0bc5d08 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -183,5 +183,26 @@ class CalendarSocialApp(Flask): return render_template('event-edit.html', form=form) + @staticmethod + @route('/settings', methods=['GET', 'POST']) + @login_required + def settings(): + """View for user settings + """ + + from .forms import SettingsForm + from .models import db + + form = SettingsForm(current_user) + + if form.validate_on_submit(): + form.populate_obj(current_user) + + db.session.commit() + + return redirect(url_for('hello')) + + return render_template('user-settings.html', form=form) + app = CalendarSocialApp(__name__) diff --git a/calsocial/forms.py b/calsocial/forms.py index a5973eb..7e17a06 100644 --- a/calsocial/forms.py +++ b/calsocial/forms.py @@ -135,3 +135,27 @@ class EventForm(FlaskForm): if field.data < self.start_time.data: raise ValidationError(_('End time must be later than start time!')) + + +class SettingsForm(FlaskForm): + """Form for user settings + """ + + timezone = TimezoneField(_('Time zone'), validators=[DataRequired()]) + + def __init__(self, user, *args, **kwargs): + self.user = user + + kwargs.setdefault('timezone', user.timezone) + + FlaskForm.__init__(self, *args, **kwargs) + + def populate_obj(self, user): + """Populate ``obj`` with event data + """ + + for name, field in self._fields.items(): + if not (hasattr(self.__class__, name) and not hasattr(FlaskForm, name)): + continue + + user.settings[name] = str(field.data) diff --git a/calsocial/templates/base.html b/calsocial/templates/base.html index df70f3f..f06841c 100644 --- a/calsocial/templates/base.html +++ b/calsocial/templates/base.html @@ -38,6 +38,7 @@ {% else %}