Ejemplo n.º 1
0
def school_form(school_id=INVALID_ID):
    if not session.get('program_id'):
        return redirect(url_for('program'))
    if school_id == INVALID_ID:
        id_of_school_being_added = DatabaseManager.id_of_school_being_added(FILL_STR_SCHOOL)
        if not id_of_school_being_added:
            new_school = School(nick=FILL_STR_SCHOOL, name=FILL_STR_SCHOOL,
                                address=FILL_STR_SCHOOL,
                                city=FILL_STR_SCHOOL, regon=FILL_STR_SCHOOL,
                                email=FILL_STR_SCHOOL, responsible_person=FILL_STR_SCHOOL + FILL_BY_SCHOOL,
                                phone=FILL_STR_SCHOOL + FILL_BY_SCHOOL)
            if DatabaseManager.add_row(new_school):
                return redirect(url_for('school_form', school_id=new_school.id, School=new_school))
            else:
                return redirect(url_for('school_form', school_id=INVALID_ID))
        else:
            return redirect(
                url_for('school_form', school_id=id_of_school_being_added.id, School=id_of_school_being_added))

    current_school = DatabaseManager.get_school(school_id)
    if request.method == 'POST':
        data_to_update = {"nick": empty_if_none(request.form["nick"]), "name": empty_if_none(request.form["name"]),
                          "address": empty_if_none(request.form["address"]),
                          "city": empty_if_none(request.form["city"]),
                          "nip": empty_if_none(request.form["nip"]), "regon": empty_if_none(request.form["regon"]),
                          "email": empty_if_none(request.form["email"]), "phone": empty_if_none(request.form["phone"]),
                          "responsible_person": empty_if_none(request.form["responsible_person"]),
                          "representative": empty_if_none(request.form["representative"]),
                          "representative_nip": empty_if_none(request.form["representative_nip"]),
                          "representative_regon": empty_if_none(request.form["representative_regon"])}
        school_id = DatabaseManager.update_school_data(current_school, **data_to_update)
        return redirect(url_for('school_form', school_id=current_school.id))
    return render_template("school_form.html", School=current_school,
                           Contracts=DatabaseManager.get_all_contracts(school_id, session.get('program_id')))
Ejemplo n.º 2
0
def contract_delete(school_id, contract_id):
    if not str(session.get('program_id')):
        return redirect(url_for('program'))
    DatabaseManager.remove_contract(contract_id)
    return render_template("school_form.html", School=DatabaseManager.get_school(school_id),
                           Contracts=DatabaseManager.get_all_contracts(school_id, session.get('program_id')))