EditionPN/app/routes.py

116 lines
4.3 KiB
Python
Raw Normal View History

2021-05-06 10:26:28 +02:00
from flask import render_template, flash, redirect, url_for, request
from app import app, db
2021-05-06 10:26:28 +02:00
from app.forms import *
import app.models as models
2021-05-06 10:26:28 +02:00
import yaml
@app.route("/")
@app.route("/index")
def index():
return render_template("base.html")
@app.route("/PN", methods=["GET","POST"])
def PN():
form = PNForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.PN.query.all()]
2021-05-06 10:26:28 +02:00
form_validation = form.validate_on_submit()
form = form_import(form)
2021-05-07 12:32:10 +02:00
form = form_charger(form)
if form_validation and not form.charger.data:
if form.exporter.data:
flash("Ajout du référentiel PN: {} ".format(form.code.data))
form_export(form)
if form.sauvegarder.data:
2021-05-06 19:26:09 +02:00
pn = models.PN.query.filter_by(code=form.code.data).first()
if pn == None:
pn = models.PN()
form.populate_obj(pn)
db.session.add(pn)
db.session.commit()
2021-05-06 10:26:28 +02:00
return redirect(url_for("PN"))
return render_template("PN.html", form = form)
@app.route("/AC", methods=["GET","POST"])
def AC():
2021-05-06 12:19:06 +02:00
form = ACForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.AC.query.all()]
2021-05-06 12:19:06 +02:00
form_validation = form.validate_on_submit()
form = form_import(form)
2021-05-07 12:32:10 +02:00
form = form_charger(form)
if form_validation and not form.charger.data:
if form.exporter.data:
flash("Ajout du référentiel AC: {} ".format(form.code.data))
form_export(form)
2021-05-06 19:26:09 +02:00
if form.sauvegarder.data:
ac = models.AC.query.filter_by(code=form.code.data).first()
if ac == None:
ac = models.AC()
form.populate_obj(ac)
db.session.add(ac)
db.session.commit()
2021-05-06 12:19:06 +02:00
return redirect(url_for("AC"))
return render_template("AC.html", form = form)
2021-05-06 10:26:28 +02:00
@app.route("/SAE", methods=["GET","POST"])
def SAE():
form = SAEForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.SAE.query.all()]
2021-05-06 10:26:28 +02:00
form_validation = form.validate_on_submit()
form = form_import(form)
2021-05-07 12:32:10 +02:00
form = form_charger(form)
if form_validation and not form.charger.data:
if form.exporter.data:
flash("Ajout du référentiel SAE: {} ".format(form.code.data))
form_export(form)
2021-05-06 19:26:09 +02:00
if form.sauvegarder.data:
sae = models.SAE.query.filter_by(code=form.code.data).first()
if sae == None:
sae = models.SAE()
form.populate_obj(sae)
db.session.add(sae)
db.session.commit()
2021-05-06 10:26:28 +02:00
return redirect(url_for("SAE"))
return render_template("SAE.html", form = form)
@app.route("/Ressource", methods=["GET","POST"])
def Ressource():
form = RessourceForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.Ressource.query.all()]
2021-05-06 10:26:28 +02:00
form_validation = form.validate_on_submit()
form = form_import(form)
2021-05-07 12:32:10 +02:00
form = form_charger(form)
if form_validation and not form.charger.data:
if form.exporter.data:
flash("Ajout du référentiel Ressource: {} ".format(form.code.data))
form_export(form)
2021-05-06 19:26:09 +02:00
if form.sauvegarder.data:
ressource = models.Ressource.query.filter_by(code=form.code.data).first()
if ressource == None:
ressource = models.Ressource()
form.populate_obj(ressource)
db.session.add(ressource)
db.session.commit()
2021-05-06 10:26:28 +02:00
return redirect(url_for("Ressource"))
return render_template("Ressource.html", form = form)
@app.route("/Competence", methods=["GET","POST"])
def Competence():
form = CompetenceForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.Competence.query.all()]
2021-05-06 10:26:28 +02:00
form_validation = form.validate_on_submit()
form = form_import(form)
2021-05-07 12:32:10 +02:00
form = form_charger(form)
if form_validation and not form.charger.data:
if form.exporter.data:
flash("Ajout du référentielCompetence: {} ".format(form.code.data))
form_export(form)
2021-05-06 19:26:09 +02:00
if form.sauvegarder.data:
competence = models.Competence.query.filter_by(code=form.code.data).first()
if competence == None:
competence = models.Competence()
form.populate_obj(competence)
db.session.add(competence)
db.session.commit()
2021-05-06 10:26:28 +02:00
return redirect(url_for("Competence"))
return render_template("Competence.html", form = form)