Esempio n. 1
0
def choose_role():
    form = RoleSignupForm()

    form.add_roles(Role.get_all())
    current_volunteer = VolunteerUser.get_for_user(current_user)

    if form.validate_on_submit():
        current_role_ids = [r.id for r in current_volunteer.interested_roles]

        for r in form.roles:
            r_id = r._role.id
            if r.signup.data and r_id not in current_role_ids:
                current_volunteer.interested_roles.append(r._role)

            elif not r.signup.data and r_id in current_role_ids:
                current_volunteer.interested_roles.remove(r._role)

        db.session.commit()
        flash("Your role list has been updated", 'info')
        return redirect(url_for('.choose_role'))

    current_roles = current_volunteer.interested_roles.all()
    if current_roles:
        role_ids = [r.id for r in current_roles]
        form.select_roles(role_ids)

    return render_template('volunteer/choose_role.html', form=form)
Esempio n. 2
0
def _get_interested_roles(user):
    roles = Role.get_all()
    volunteer = Volunteer.get_for_user(user)
    res = []

    for r in roles:
        to_add = r.to_dict()
        to_add["is_interested"] = r in volunteer.interested_roles
        to_add["is_trained"] = r in volunteer.trained_roles

        res.append(to_add)

    return res
Esempio n. 3
0
def select_training():
    return render_template("volunteer/training/select_training.html",
                           roles=Role.get_all())