Fix: AC suppr -> Coef de l'AC suppr

This commit is contained in:
Éric Li 2021-06-10 17:05:57 +02:00
parent 22b2325774
commit c843bfd478
2 changed files with 27 additions and 17 deletions

View File

@ -47,29 +47,31 @@ class Competence(db.Model):
niveaux = db.Column(db.Text(), info={'label': 'Niveaux'})
acs = db.relationship("AC", order_by="AC.code", secondary=ACs_Competences, lazy=False, backref=db.backref("competences", lazy=False))
def updateCoefSAE(self, saes, coef=0):
def updateCoefSAE(self, saes, query, coef=0):
listeSAE = [coefsae.sae for coefsae in self.saes]
for sae in saes:
if sae in listeSAE:
CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef
listeSAE.remove(sae)
else:
self.saes.append(CoefSAE(competence=self, sae=sae, coef=coef))
if sae in query:
if sae in listeSAE:
CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef
listeSAE.remove(sae)
else:
self.saes.append(CoefSAE(competence=self, sae=sae, coef=coef))
for sae in listeSAE:
db.session.delete(CoefSAE.query.filter_by(sae=sae, competence=self).first())
db.session.commit()
db.session.commit()
def updateCoefRessource(self, ressources, coef=0):
def updateCoefRessource(self, ressources, query, coef=0):
listeRessource = [coefressource.ressource for coefressource in self.ressources]
for ressource in ressources:
if ressource in listeRessource:
CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef
listeRessource.remove(ressource)
else:
self.ressources.append(CoefRessource(competence=self, ressource=ressource, coef=coef))
if ressource in query:
if ressource in listeRessource:
CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef
listeRessource.remove(ressource)
else:
self.ressources.append(CoefRessource(competence=self, ressource=ressource, coef=coef))
for ressource in listeRessource:
db.session.delete(CoefRessource.query.filter_by(ressource=ressource, competence=self).first())
db.session.commit()
db.session.commit()
def export(self):
result = dict(self.__dict__)

View File

@ -51,13 +51,21 @@ def Semestre(num):
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)
# 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)
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:
if objetformation in querySAE or objetformation in queryRessource:
objetformation.setCoef(coeffield.coef.data, ue)
db.session.commit()
return redirect(url_for("Semestre", num=num))