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,9 +47,10 @@ 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 query:
if sae in listeSAE:
CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef
listeSAE.remove(sae)
@ -59,9 +60,10 @@ class Competence(db.Model):
db.session.delete(CoefSAE.query.filter_by(sae=sae, competence=self).first())
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 query:
if ressource in listeRessource:
CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef
listeRessource.remove(ressource)

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))