Exemplo n.º 1
0
def userDashboard():
    # define an error variable to be passed through if any errors that need to be prompted to the user occur
    error = None
    skill_form = SkillForm()
    # checks for a post request from the form submit button
    if request.method == 'POST':
        # if the validation from the wtform class passes continue
        if skill_form.validate_on_submit():
            skills = []
            for skill in current_user.get_skills():
                skills.append(skill.skillType)
            if skill_form.skill.data not in skills:
                new_skill = Skill(skill_form.skill.data, current_user.id)
                # add and commit to the database
                db.session.add(new_skill)
                db.session.commit()
                return redirect(url_for('dashboard.userDashboard'))
            else:
                error = "You have all ready added that skill."
        else:
            error = "Invalid Skill Selected."
    # query all volunteers and duties
    volunteers = Volunteer.query.filter_by(isActive = True)
    duties = Duty.query.all()
    # check for admin, if so load the duty creator and location creator forms
    if current_user.isAdmin:
        # get all applying volunteers
        applying_volunteers = Volunteer.query.filter_by(isActive = False)
        duty_form = DutyForm()
        duty_form.volunteer.choices = [(volunteer.id, volunteer.firstname) for volunteer in Volunteer.query.all()]
        duty_form.location.choices = [(location.id, location.name) for location in Location.query.all()]
        location_form = LocationForm()
        # render the admin dashboard
        return render_template('dashboard/admin-dashboard.html',
        volunteers=volunteers, duties=duties,duty_form=duty_form,location_form=location_form
        ,applying_volunteers=applying_volunteers, sorted_volunteers=volunteerShiftSort(), skill_form=skill_form, error=error)
    # otherwise if the user is a volunteer and not an administrator then load the volunteer dashboard
    else:
        return render_template('dashboard/volunteer-dashboard.html', volunteers=volunteers, sorted_volunteers=volunteerShiftSort(),
        skill_form=skill_form, error = error)
Exemplo n.º 2
0
def addSkill():
# define an error variable to be passed through if any errors that need to be prompted to the user occur
    error = None
    skill_form = SkillForm()
    # checks for a post request from the form submit button
    if request.method == 'POST':
        # if the validation from the wtform class passes continue
        if skill_form.validate_on_submit():
            skills = []
            for skill in current_user.get_skills():
                skills.append(skill.skillType)
            if skill_form.skill.data not in skills:
                new_skill = Skill(skill_form.skill.data, current_user.id)
                # add and commit to the database
                db.session.add(new_skill)
                db.session.commit()
                return redirect(url_for('dashboard.userDashboard'))
            else:
                error = "You have all ready added that skill."
        else:
            error = "Invalid Skill Selected."
    return render_template('accounts/add_skill.html', skill_form=skill_form, error=error)