forked from gergely/calendar-social
Add a view for the first steps after the initial login
This commit is contained in:
parent
41f6c88df1
commit
81d949d708
@ -109,6 +109,20 @@ class CalendarSocialApp(Flask):
|
|||||||
|
|
||||||
self.route(*args, **kwargs)(attr)
|
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
|
@property
|
||||||
def timezone(self):
|
def timezone(self):
|
||||||
"""The default time zone of the app
|
"""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))
|
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__)
|
app = CalendarSocialApp(__name__)
|
||||||
|
@ -321,3 +321,17 @@ class InviteForm(FlaskForm):
|
|||||||
raise ValidationError(_('User is already invited'))
|
raise ValidationError(_('User is already invited'))
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
pass
|
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.'))
|
||||||
|
31
calsocial/templates/first-steps.html
Normal file
31
calsocial/templates/first-steps.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{% trans %}First steps{% endtrans %}</h1>
|
||||||
|
<p>
|
||||||
|
{% trans %}Welcome to Calendar.social!{% endtrans %}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{% trans %}These are the first steps you should make before you can start using the site.{% endtrans %}
|
||||||
|
</p>
|
||||||
|
<form method="post">
|
||||||
|
{{ form.errors }}
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{ form.display_name.errors }}
|
||||||
|
{{ form.display_name.label }}
|
||||||
|
{{ form.display_name }}<br>
|
||||||
|
{{ form.display_name.description }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{ form.time_zone.errors }}
|
||||||
|
{{ form.time_zone.label }}
|
||||||
|
{{ form.time_zone }}<br>
|
||||||
|
{{ form.time_zone.description }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<button type="submit">{% trans %}Save{% endtrans %}</button>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user