def compressed_gas_cylinders():

    if request.method == 'POST':
        session['training_subject'] = 'Compressed Gas Cylinders'
        return redirect(url_for('completed'))
    if prereq_required('Hazard Communication'):
        return render_template('laboratory/compressed_gas_cylinders.html')
    else:
        return redirect(url_for('general/01.html'))
def appendix_b():

    form = GenericSubmitForm()
    if form.validate_on_submit():
        session['training_subject'] = 'Respirator Protection Program - Appendix B'
        return redirect(url_for('completed'))
    if prereq_required('Respirator Protection Program - Appendix A'):
        return render_template('hazmat/rp_appendix_b.html', form=form)
    else:
        return redirect(url_for('appendix_a'))
def appendix_a():

    form = RPP_AppendixA()
    if form.validate_on_submit():
        session['training_subject'] = 'Respirator Protection Program - Appendix A'
        return redirect(url_for('completed'))

    if prereq_required('Respirator Protection Program'):
        return render_template('hazmat/rp_appendix_a.html', form=form)
    else:
        return redirect(url_for('respirator_protection_program'))
def respirator_protection_program():

    form = RespiratorProgram1()
    if form.validate_on_submit():
        session['training_subject'] = 'Respirator Protection Program'
        return redirect(url_for('completed'))

    if prereq_required('Safety Overview'):
        return render_template('hazmat/respirator_protection_program.html', form=form)
    else:
        return redirect(url_for('safety_overview'))
def controlled_chemical_substances():

    if request.method == 'POST':
        session['training_subject'] = 'Controlled Chemical Substances'
        return redirect(url_for('completed'))
    return render_template('hazmat/controlled_chemical_substances.html')

    if prereq_required('Safety Overview'):
        return render_template('hazmat/controlled_chemical_substances.html')
    else:
        return redirect(url_for('general01'))
def hf_awareness():

    form = HydrogenFluorideQuiz()
    if form.validate_on_submit():
        session['training_subject'] = 'HF Awareness and First Aid'
        return redirect(url_for('completed'))

    if prereq_required('Hazard Communication'):
        return render_template('laboratory/hf_awareness.html', form=form)
    else:
        return redirect(url_for('hazard_communication'))
def occupational_exposure():

    form = OccExpQuiz1()
    if form.validate_on_submit():
        session['training_subject'] = 'Occupational Exposure to Hazardous Chemicals'
        return redirect(url_for('completed'))

    if prereq_required('Hazard Communication'):
        return render_template('general/occupational_exposure.html', form=form)
    else:
        return redirect(url_for('hazard_communication'))
def hazard_communication():

    form = HazComQuiz1()
    if form.validate_on_submit():
        session['training_subject'] = 'Hazard Communication'
        return redirect(url_for('completed'))

    if prereq_required('Safety Overview'):
        return render_template('general/hazard_communication.html', form=form)
    else:
        return redirect(url_for('safety_overview'))
def handling_hazmat():
    '''
    This function generates a webpage that has a quiz at the end.
    Quizzes are presented as a form.
    In this example, session['training_subject'] is the title of the training material.
    Once all answers are correct, the user will be taken to the completed page and from there,
    the training subject will be recorded in the database.

    A prerequisite training is required. In this function, it is 'Safety Overview'. If the prerequisite
    training has not been completed, it will redirect the user to the required training page. If the
    prerequisite has been satisfied, then the user will be taken to the training page.
    '''
    form = HazMatWaste1()
    if form.validate_on_submit():
        # determines if all answers are correct on the quiz
        session['training_subject'] = 'Handling Hazardous Materials and Waste'
        return redirect(url_for('completed'))
    if prereq_required('Safety Overview'):
        # the training page will be shown if the prerequisite has been satisfied
        return render_template('general/handling_hazmat.html', form=form)
    else:
        # if the prerequisite has not been satisfied, the user will be redirected to the prerequisite training
        return redirect(url_for('safety_overview'))
def IIPP():

    if prereq_required('Safety Overview'):
        return render_template('general/IIPP.html')
    else:
        return redirect(url_for('safety_overview'))