forked from eric.li/EditionPN
196 lines
8.8 KiB
Python
196 lines
8.8 KiB
Python
from flask import render_template, flash, redirect, url_for, request
|
|
from app import app, db
|
|
from app.forms import *
|
|
import app.models as models
|
|
|
|
import yaml
|
|
|
|
@app.route("/")
|
|
@app.route("/index", methods=["GET","POST"])
|
|
def index():
|
|
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()
|
|
semestres = sorted(models.Semestre.query.all(), key=lambda semestre: semestre.num)
|
|
return render_template("index.html", semestres=semestres, form=form)
|
|
|
|
@app.route("/Semestre<num>", methods=["GET","POST"])
|
|
def Semestre(num):
|
|
form = SemestreForm()
|
|
semestre = models.Semestre.query.filter_by(num=num).first()
|
|
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
|
|
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})
|
|
# Appuie sur Update
|
|
if form.update.data:
|
|
semestre.ues = [ue for ue in form.ues.data]
|
|
form.validate_on_submit()
|
|
for i, field in enumerate(form.ueform):
|
|
ue = models.Competence.query.filter_by(code=field.ue.data).first()
|
|
ue.acs = field.acs.data
|
|
ue.updateCoefSAE(field.saes.data)
|
|
ue.updateCoefRessource(field.ressources.data)
|
|
for coeffield in field.coef:
|
|
codeClass, code = coeffield.objetformation.data[1:-1].split()
|
|
model = getattr(models, codeClass)
|
|
objetformation = model.query.filter_by(code=code).first()
|
|
if objetformation in field.saes.data or objetformation in field.ressources.data:
|
|
objetformation.setCoef(coeffield.coef.data, ue)
|
|
db.session.commit()
|
|
return redirect(url_for("Semestre", num=num))
|
|
# Remplis les fields des informations que l'ue possède
|
|
for i, ue in enumerate(semestre.ues):
|
|
form.ueform.__getitem__(i).acs.process_data(ue.acs)
|
|
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))
|
|
# Coche les ues que le semestre possède
|
|
form.ues.process_data(semestre.ues)
|
|
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):
|
|
form = PNForm()
|
|
form.referentiel.choices = [x for x in models.PN.query.all()]
|
|
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:
|
|
flash("Export du référentiel PN: {} ".format(form.code.data))
|
|
form.exporterRef()
|
|
elif form.sauvegarder.data:
|
|
form.sauvegarderRef()
|
|
return redirect(url_for("PN"))
|
|
elif code:
|
|
referentiel = models.PN.query.filter_by(code="PN"+code).first()
|
|
if referentiel == None: return redirect(url_for("PN"))
|
|
else: form.chargerBDD(referentiel)
|
|
return render_template("PN.html", form = form)
|
|
|
|
@app.route("/AC", defaults={"code":None}, methods=["GET","POST"])
|
|
@app.route("/AC<code>", methods=["GET","POST"])
|
|
def AC(code):
|
|
form = ACForm()
|
|
form.referentiel.choices = [x for x in models.AC.query.all()]
|
|
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:
|
|
flash("Export du référentiel AC: {} ".format(form.code.data))
|
|
form.exporterRef()
|
|
elif form.sauvegarder.data:
|
|
form.sauvegarderRef()
|
|
return redirect(url_for("AC"))
|
|
elif code:
|
|
referentiel = models.AC.query.filter_by(code="AC"+code).first()
|
|
if referentiel == None: return redirect(url_for("AC"))
|
|
else: form.chargerBDD(referentiel)
|
|
return render_template("AC.html", form = form)
|
|
|
|
@app.route("/SAE", defaults={"code":None}, methods=["GET","POST"])
|
|
@app.route("/SAE<code>", methods=["GET","POST"])
|
|
def SAE(code):
|
|
form = SAEForm()
|
|
form.referentiel.choices = [x for x in models.SAE.query.all()]
|
|
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:
|
|
flash("Export du référentiel SAE: {} ".format(form.code.data))
|
|
form.exporterRef()
|
|
elif form.sauvegarder.data:
|
|
form.sauvegarderRef()
|
|
return redirect(url_for("SAE"))
|
|
elif code:
|
|
referentiel = models.SAE.query.filter_by(code="SAE"+code).first()
|
|
if referentiel == None: return redirect(url_for("SAE"))
|
|
else: form.chargerBDD(referentiel)
|
|
return render_template("SAE.html", form = form)
|
|
|
|
@app.route("/Ressource", defaults={"code":None}, methods=["GET","POST"])
|
|
@app.route("/Ressource<code>", methods=["GET","POST"])
|
|
def Ressource(code):
|
|
form = RessourceForm()
|
|
form.referentiel.choices = [x for x in models.Ressource.query.all()]
|
|
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:
|
|
flash("Export du référentiel Ressource: {} ".format(form.code.data))
|
|
form.exporterRef()
|
|
elif form.sauvegarder.data:
|
|
form.sauvegarderRef()
|
|
return redirect(url_for("Ressource"))
|
|
elif code:
|
|
referentiel = models.Ressource.query.filter_by(code="R"+code).first()
|
|
if referentiel == None: return redirect(url_for("Ressource"))
|
|
else: form.chargerBDD(referentiel)
|
|
return render_template("Ressource.html", form = form)
|
|
|
|
@app.route("/Competence", defaults={"code":None}, methods=["GET","POST"])
|
|
@app.route("/Competence<code>", methods=["GET","POST"])
|
|
def Competence(code):
|
|
form = CompetenceForm()
|
|
form.referentiel.choices = [x for x in models.Competence.query.all()]
|
|
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:
|
|
if form.supprimerRef(): return redirect(url_for("Competence"))
|
|
elif form.validate_on_submit() and not form.charger.data:
|
|
if form.exporter.data:
|
|
flash("Export du référentielCompetence: {} ".format(form.code.data))
|
|
form.exporterRef()
|
|
if form.sauvegarder.data:
|
|
form.sauvegarderRef()
|
|
return redirect(url_for("Competence"))
|
|
elif code:
|
|
referentiel = models.Competence.query.filter_by(code="RT"+code).first()
|
|
if referentiel == None: return redirect(url_for("Competence"))
|
|
else: form.chargerBDD(referentiel)
|
|
return render_template("Competence.html", form = form) |