EditionPN/app/routes.py

209 lines
9.5 KiB
Python
Raw Normal View History

2021-06-09 12:48:24 +02:00
from flask import render_template, flash, redirect, url_for
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
2021-06-11 14:25:33 +02:00
@app.route("/", methods=["GET","POST"])
2021-06-01 19:31:24 +02:00
@app.route("/index", methods=["GET","POST"])
2021-05-06 10:26:28 +02:00
def index():
2021-06-01 19:31:24 +02:00
form = AccueilForm()
if form.ajouter.data:
for i in range(1,7):
semestre = models.Semestre(num=i)
db.session.add(semestre)
db.session.commit()
elif form.reset.data:
for semestre in models.Semestre.query.all():
db.session.delete(semestre)
db.session.commit()
2021-06-09 12:19:14 +02:00
elif form.exporterJSON.data:
form.exportJSON()
elif form.exporterYAML.data:
form.exportYAML()
2021-06-01 19:31:24 +02:00
semestres = sorted(models.Semestre.query.all(), key=lambda semestre: semestre.num)
return render_template("index.html", semestres=semestres, form=form)
2021-05-06 10:26:28 +02:00
2021-06-01 19:31:24 +02:00
@app.route("/Semestre<num>", methods=["GET","POST"])
def Semestre(num):
form = SemestreForm()
semestre = models.Semestre.query.filter_by(num=num).first()
if semestre == None:
flash("Ce Semestre n'existe pas!", "error")
return redirect(url_for("index"))
2021-06-01 19:31:24 +02:00
for i, ue in enumerate(semestre.ues):
if form.ueform.__len__() < len(semestre.ues): form.ueform.append_entry(data={"ue": ue.code})
# Donne aux dropdowns la liste des objets de formations que les ACs possèdent sans doublons
querySAE = []
queryRessource = []
for ac in ue.acs:
for sae in ac.saes:
if sae not in querySAE: querySAE.append(sae)
for ressource in ac.ressources:
if ressource not in queryRessource: queryRessource.append(ressource)
form.ueform.__getitem__(i).saes.query=querySAE
form.ueform.__getitem__(i).ressources.query=queryRessource
2021-06-09 10:21:19 +02:00
if not form.update.data:
for coefsae in ue.saes:
form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefsae.sae})
for coefressource in ue.ressources:
form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefressource.ressource})
2021-06-01 19:31:24 +02:00
# Appuie sur Update
if form.update.data:
semestre.ues = [ue for ue in form.ues.data]
2021-06-09 10:21:19 +02:00
form.validate_on_submit()
2021-06-01 19:31:24 +02:00
for i, field in enumerate(form.ueform):
ue = models.Competence.query.filter_by(code=field.ue.data).first()
ue.acs = field.acs.data
2021-06-10 17:05:57 +02:00
# Fabrique la liste des Coefs qui ne doit pas être supprimé suite à un éventuel suppression d'un AC
querySAE = []
queryRessource = []
for ac in ue.acs:
for sae in ac.saes:
if sae not in querySAE: querySAE.append(sae)
for ressource in ac.ressources:
if ressource not in queryRessource: queryRessource.append(ressource)
ue.updateCoefSAE(field.saes.data, querySAE)
ue.updateCoefRessource(field.ressources.data, queryRessource)
2021-06-09 10:21:19 +02:00
for coeffield in field.coef:
codeClass, code = coeffield.objetformation.data[1:-1].split()
model = getattr(models, codeClass)
2021-06-09 10:36:48 +02:00
objetformation = model.query.filter_by(code=code).first()
2021-06-10 17:05:57 +02:00
if objetformation in querySAE or objetformation in queryRessource:
2021-06-09 10:36:48 +02:00
objetformation.setCoef(coeffield.coef.data, ue)
2021-06-01 19:31:24 +02:00
db.session.commit()
return redirect(url_for("Semestre", num=num))
2021-06-09 10:21:19 +02:00
# Remplis les fields des informations que l'ue possède
2021-06-01 19:31:24 +02:00
for i, ue in enumerate(semestre.ues):
form.ueform.__getitem__(i).acs.process_data(ue.acs)
2021-06-09 10:21:19 +02:00
form.ueform.__getitem__(i).saes.process_data([coefsae.sae for coefsae in ue.saes])
form.ueform.__getitem__(i).ressources.process_data([coefressource.ressource for coefressource in ue.ressources])
for field in form.ueform.__getitem__(i).coef:
field.coef.process_data(field.objetformation.data.getCoef(ue))
2021-06-01 19:31:24 +02:00
# Coche les ues que le semestre possède
2021-06-09 10:21:19 +02:00
form.ues.process_data(semestre.ues)
2021-06-01 19:31:24 +02:00
return render_template("semestre.html", semestre=semestre, form=form)
@app.route("/PN", defaults={"code":None}, methods=["GET","POST"])
@app.route("/PN<code>", methods=["GET","POST"])
def PN(code):
2021-05-06 10:26:28 +02:00
form = PNForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.PN.query.all()]
2021-06-01 19:31:24 +02:00
form.validate_on_submit()
if form.charger.data:
if form.chargerRef(): return redirect(url_for("PN", code=form.referentiel.data.split()[1][2:-1]))
elif form.importer.data:
form.importerRef()
elif form.supprimer.data:
if form.supprimerRef(): return redirect(url_for("PN"))
elif form.validate_on_submit() and not form.charger.data:
if form.exporter.data:
2021-06-01 19:31:24 +02:00
flash("Export du référentiel PN: {} ".format(form.code.data))
form.exporterRef()
elif form.sauvegarder.data:
form.sauvegarderRef()
2021-05-06 10:26:28 +02:00
return redirect(url_for("PN"))
2021-06-01 19:31:24 +02:00
elif code:
referentiel = models.PN.query.filter_by(code="PN"+code).first()
if referentiel == None: return redirect(url_for("PN"))
else: form.chargerBDD(referentiel)
2021-05-06 10:26:28 +02:00
return render_template("PN.html", form = form)
2021-06-01 19:31:24 +02:00
@app.route("/AC", defaults={"code":None}, methods=["GET","POST"])
@app.route("/AC<code>", methods=["GET","POST"])
def AC(code):
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-06-01 19:31:24 +02:00
form.validate_on_submit()
if form.charger.data:
if form.chargerRef(): return redirect(url_for("AC", code=form.referentiel.data.split()[1][2:-1]))
elif form.importer.data:
form.importerRef()
elif form.supprimer.data:
if form.supprimerRef(): return redirect(url_for("AC"))
elif form.validate_on_submit() and not form.charger.data:
if form.exporter.data:
2021-06-01 19:31:24 +02:00
flash("Export du référentiel AC: {} ".format(form.code.data))
form.exporterRef()
elif form.sauvegarder.data:
form.sauvegarderRef()
2021-05-06 12:19:06 +02:00
return redirect(url_for("AC"))
2021-06-01 19:31:24 +02:00
elif code:
referentiel = models.AC.query.filter_by(code="AC"+code).first()
if referentiel == None: return redirect(url_for("AC"))
else: form.chargerBDD(referentiel)
2021-05-06 12:19:06 +02:00
return render_template("AC.html", form = form)
2021-05-06 10:26:28 +02:00
2021-06-01 19:31:24 +02:00
@app.route("/SAE", defaults={"code":None}, methods=["GET","POST"])
@app.route("/SAE<code>", methods=["GET","POST"])
def SAE(code):
2021-05-06 10:26:28 +02:00
form = SAEForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.SAE.query.all()]
2021-06-01 19:31:24 +02:00
form.validate_on_submit()
if form.charger.data:
if form.chargerRef(): return redirect(url_for("SAE", code=form.referentiel.data.split()[1][3:-1]))
elif form.importer.data:
form.importerRef()
elif form.supprimer.data:
if form.supprimerRef(): return redirect(url_for("SAE"))
elif form.validate_on_submit() and not form.charger.data:
if form.exporter.data:
2021-06-01 19:31:24 +02:00
flash("Export du référentiel SAE: {} ".format(form.code.data))
form.exporterRef()
elif form.sauvegarder.data:
form.sauvegarderRef()
2021-05-06 10:26:28 +02:00
return redirect(url_for("SAE"))
2021-06-01 19:31:24 +02:00
elif code:
referentiel = models.SAE.query.filter_by(code="SAE"+code).first()
if referentiel == None: return redirect(url_for("SAE"))
else: form.chargerBDD(referentiel)
2021-05-06 10:26:28 +02:00
return render_template("SAE.html", form = form)
2021-06-01 19:31:24 +02:00
@app.route("/Ressource", defaults={"code":None}, methods=["GET","POST"])
@app.route("/Ressource<code>", methods=["GET","POST"])
def Ressource(code):
2021-05-06 10:26:28 +02:00
form = RessourceForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.Ressource.query.all()]
2021-06-01 19:31:24 +02:00
form.validate_on_submit()
if form.charger.data:
if form.chargerRef(): return redirect(url_for("Ressource", code=form.referentiel.data.split()[1][1:-1]))
elif form.importer.data:
form.importerRef()
elif form.supprimer.data:
if form.supprimerRef(): return redirect(url_for("Ressource"))
elif form.validate_on_submit() and not form.charger.data:
if form.exporter.data:
2021-06-01 19:31:24 +02:00
flash("Export du référentiel Ressource: {} ".format(form.code.data))
form.exporterRef()
elif form.sauvegarder.data:
form.sauvegarderRef()
2021-05-06 10:26:28 +02:00
return redirect(url_for("Ressource"))
2021-06-01 19:31:24 +02:00
elif code:
referentiel = models.Ressource.query.filter_by(code="R"+code).first()
if referentiel == None: return redirect(url_for("Ressource"))
else: form.chargerBDD(referentiel)
2021-05-06 10:26:28 +02:00
return render_template("Ressource.html", form = form)
2021-06-01 19:31:24 +02:00
@app.route("/Competence", defaults={"code":None}, methods=["GET","POST"])
@app.route("/Competence<code>", methods=["GET","POST"])
def Competence(code):
2021-05-06 10:26:28 +02:00
form = CompetenceForm()
2021-05-06 19:26:09 +02:00
form.referentiel.choices = [x for x in models.Competence.query.all()]
2021-06-01 19:31:24 +02:00
form.validate_on_submit()
if form.charger.data:
if form.chargerRef(): return redirect(url_for("Competence", code=form.referentiel.data.split()[1][2:-1]))
elif form.importer.data:
form.importerRef()
elif form.supprimer.data:
2021-06-09 10:21:19 +02:00
if form.supprimerRef(): return redirect(url_for("Competence"))
2021-06-01 19:31:24 +02:00
elif form.validate_on_submit() and not form.charger.data:
if form.exporter.data:
2021-06-01 19:31:24 +02:00
flash("Export du référentielCompetence: {} ".format(form.code.data))
form.exporterRef()
if form.sauvegarder.data:
form.sauvegarderRef()
2021-05-06 10:26:28 +02:00
return redirect(url_for("Competence"))
2021-06-01 19:31:24 +02:00
elif code:
referentiel = models.Competence.query.filter_by(code="RT"+code).first()
if referentiel == None: return redirect(url_for("Competence"))
else: form.chargerBDD(referentiel)
2021-05-06 10:26:28 +02:00
return render_template("Competence.html", form = form)