From 81d949d70843d823210dbd66b2ad0f1dffa80457 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 10 Jul 2018 16:38:53 +0200 Subject: [PATCH] Add a view for the first steps after the initial login --- calsocial/__init__.py | 41 ++++++++++++++++++++++++++++ calsocial/forms.py | 14 ++++++++++ calsocial/templates/first-steps.html | 31 +++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 calsocial/templates/first-steps.html diff --git a/calsocial/__init__.py b/calsocial/__init__.py index d449faa..9b4e3b1 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -109,6 +109,20 @@ class CalendarSocialApp(Flask): self.route(*args, **kwargs)(attr) + self.before_request(self.goto_first_steps) + + @staticmethod + def goto_first_steps(): + """Check if the current user has a profile and if not, redirect to the first steps page + """ + + if current_user.is_authenticated and \ + not current_user.profile and \ + request.endpoint != 'first_steps': + return redirect(url_for('first_steps')) + + return None + @property def timezone(self): """The default time zone of the app @@ -358,5 +372,32 @@ class CalendarSocialApp(Flask): return redirect(url_for('event_details', event_uuid=invitation.event.event_uuid)) + @staticmethod + @route('/first-steps', methods=['GET', 'POST']) + @login_required + def first_steps(): + """View to set up a new registrant’s profile + """ + + from .forms import FirstStepsForm + from .models import db, Profile + + if current_user.profile: + return redirect(url_for('hello')) + + form = FirstStepsForm() + + if form.validate_on_submit(): + profile = Profile(user=current_user, display_name=form.display_name.data) + db.session.add(profile) + + current_user.settings['timezone'] = str(form.time_zone.data) + + db.session.commit() + + return redirect(url_for('hello')) + + return render_template('first-steps.html', form=form) + app = CalendarSocialApp(__name__) diff --git a/calsocial/forms.py b/calsocial/forms.py index da72b2a..06fdcfc 100644 --- a/calsocial/forms.py +++ b/calsocial/forms.py @@ -321,3 +321,17 @@ class InviteForm(FlaskForm): raise ValidationError(_('User is already invited')) except NoResultFound: pass + + +class FirstStepsForm(FlaskForm): + """Form for the initial profile setup + """ + + display_name = StringField( + label=_('Display name'), + validators=[DataRequired()], + description=_('This will be shown to other users as your name. You can use your real name, or any nickname you like.')) + time_zone = TimezoneField( + label=_('Your time zone'), + validators=[DataRequired()], + description=_('The start and end times of events will be displayed in this time zone.')) diff --git a/calsocial/templates/first-steps.html b/calsocial/templates/first-steps.html new file mode 100644 index 0000000..faf6249 --- /dev/null +++ b/calsocial/templates/first-steps.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} + +{% block content %} +

{% trans %}First steps{% endtrans %}

+

+ {% trans %}Welcome to Calendar.social!{% endtrans %} +

+

+ {% trans %}These are the first steps you should make before you can start using the site.{% endtrans %} +

+
+ {{ form.errors }} + {{ form.hidden_tag() }} + +

+ {{ form.display_name.errors }} + {{ form.display_name.label }} + {{ form.display_name }}
+ {{ form.display_name.description }} +

+ +

+ {{ form.time_zone.errors }} + {{ form.time_zone.label }} + {{ form.time_zone }}
+ {{ form.time_zone.description }} +

+ + +
+{% endblock content %} -- 2.40.1