Esempio n. 1
0
def sign_up():
    form = VolunteerSignUpForm()

    if current_user.is_authenticated and VolunteerUser.get_for_user(
            current_user):
        return redirect(url_for(".schedule"))

    if request.method != "POST" and current_user.is_authenticated:
        form.volunteer_email.data = current_user.email
        form.nickname.data = current_user.name
        # Can't try to process age, as that's only submitted as part of the outreach questions

    if form.validate_on_submit():
        if current_user.is_anonymous:
            create_current_user(form.volunteer_email.data, form.nickname.data)

        new_volunteer = VolunteerUser()
        new_volunteer.user_id = current_user.id
        new_volunteer = update_volunteer_from_form(new_volunteer, form)
        db.session.add(new_volunteer)

        # On sign up give user 'volunteer' permission (+ managers etc.)
        current_user.grant_permission("volunteer:user")

        db.session.commit()
        app.logger.info("Add volunteer: %s", new_volunteer)
        flash("Thank you for signing up!", "message")
        return redirect(url_for(".choose_role"))

    return render_template("volunteer/sign-up.html",
                           user=current_user,
                           form=form)
Esempio n. 2
0
def sign_up():
    form = VolunteerSignUpForm()
    # On sign up give user 'volunteer' permission (+ managers etc.)

    if current_user.is_authenticated and VolunteerUser.get_for_user(current_user):
        return redirect(url_for('.account'))

    if request.method != 'POST' and current_user.is_authenticated:
        form.volunteer_email.data = current_user.email
        form.nickname.data = current_user.name
        form.volunteer_phone.data = current_user.phone
        # Can't copy age, as that's only submitted as part of the outreach questions

    if form.validate_on_submit():
        if current_user.is_anonymous:
            create_current_user(form.volunteer_email.data, form.nickname.data)

        new_volunteer = VolunteerUser()
        new_volunteer.user_id = current_user.id
        new_volunteer = update_volunteer_from_form(new_volunteer, form)
        db.session.add(new_volunteer)

        current_user.grant_permission('volunteer:user')

        db.session.commit()
        app.logger.info('Add volunteer: %s', new_volunteer)
        flash('Thank you for signing up!', 'message')
        return redirect(url_for('.choose_role'))

    return render_template('volunteer/sign-up.html',
                           user=current_user,
                           form=form)
Esempio n. 3
0
def sign_up():
    form = VolunteerSignUpForm()
    form.arrival.choices = generate_arrival_options()
    form.departure.choices = generate_departure_options()

    if current_user.is_authenticated and VolunteerUser.get_for_user(
            current_user):
        return redirect(url_for(".account"))

    if request.method != "POST" and current_user.is_authenticated:
        form.volunteer_email.data = current_user.email
        form.nickname.data = current_user.name
        form.volunteer_phone.data = current_user.phone
        # Can't try to process age, as that's only submitted as part of the outreach questions

    if form.validate_on_submit():
        if current_user.is_anonymous:
            create_current_user(form.volunteer_email.data, form.nickname.data)

        new_volunteer = VolunteerUser()
        new_volunteer.user_id = current_user.id
        new_volunteer = update_volunteer_from_form(new_volunteer, form)
        db.session.add(new_volunteer)

        # On sign up give user 'volunteer' permission (+ managers etc.)
        current_user.grant_permission("volunteer:user")

        db.session.commit()
        app.logger.info("Add volunteer: %s", new_volunteer)
        flash("Thank you for signing up!", "message")
        return redirect(url_for(".choose_role"))

    # Set form default arrival and departure dates to be start and end
    form.arrival.data = event_start().strftime("%F")
    form.departure.data = event_end().strftime("%F")

    return render_template("volunteer/sign-up.html",
                           user=current_user,
                           form=form)