Exemple #1
0
def add_laboratory():
    form = LaboratoryValidForm()

    if request.method == 'GET':
        return render_template('laboratory/add_laboratory.html',
                               form=form,
                               form_name="add laboratory form")
    else:
        if form.validate():
            new_lab = ormLaboratory(
                laboratory_name=form.laboratory_name.data,
                laboratory_subject=form.laboratory_subject.data,
                laboratory_mark=form.laboratory_mark.data)

            try:
                db.session.add(new_lab)
                db.session.commit()
                return redirect('/laboratory')
            except:
                form.laboratory_name.errors = [
                    'Laboratory with this name already exists!'
                ]
                return render_template('laboratory/add_laboratory.html',
                                       form=form,
                                       form_name="add laboratory form")

        else:
            return render_template('laboratory/add_laboratory.html',
                                   form=form,
                                   form_name="add laboratory form")
Exemple #2
0
def edit_laboratory(current_laboratory):
    laboratory = db.session.query(ormLaboratory).filter(
        ormLaboratory.laboratory_name == current_laboratory).one()
    form = LaboratoryValidForm()

    if request.method == 'GET':

        form.laboratory_name.data = laboratory.laboratory_name
        form.laboratory_subject.data = laboratory.laboratory_subject
        form.laboratory_mark.data = laboratory.laboratory_mark

        return render_template('laboratory/laboratory_edit_page.html',
                               form=form,
                               form_name="Edit laboratory")

    else:

        if form.validate():
            laboratory.laboratory_name = form.laboratory_name.data
            laboratory.laboratory_subject = form.laboratory_subject.data
            laboratory.laboratory_mark = form.laboratory_mark.data

            try:
                db.session.commit()
                return redirect('/laboratory')
            except:
                form.laboratory_name.errors = [
                    'Laboratory with this name already exists!'
                ]
                return render_template('laboratory/laboratory_edit_page.html',
                                       form=form,
                                       form_name="Edit laboratory")

        else:
            return render_template('laboratory/laboratory_edit_page.html',
                                   form=form,
                                   form_name="Edit laboratory")