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'}) 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)) 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] listeSAE = [coefsae.sae for coefsae in self.saes]
for sae in saes: for sae in saes:
if sae in listeSAE: if sae in query:
CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef if sae in listeSAE:
listeSAE.remove(sae) CoefSAE.query.filter_by(sae=sae, competence=self).first().coef = coef
else: listeSAE.remove(sae)
self.saes.append(CoefSAE(competence=self, sae=sae, coef=coef)) else:
self.saes.append(CoefSAE(competence=self, sae=sae, coef=coef))
for sae in listeSAE: for sae in listeSAE:
db.session.delete(CoefSAE.query.filter_by(sae=sae, competence=self).first()) 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] listeRessource = [coefressource.ressource for coefressource in self.ressources]
for ressource in ressources: for ressource in ressources:
if ressource in listeRessource: if ressource in query:
CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef if ressource in listeRessource:
listeRessource.remove(ressource) CoefRessource.query.filter_by(ressource=ressource, competence=self).first().coef = coef
else: listeRessource.remove(ressource)
self.ressources.append(CoefRessource(competence=self, ressource=ressource, coef=coef)) else:
self.ressources.append(CoefRessource(competence=self, ressource=ressource, coef=coef))
for ressource in listeRessource: for ressource in listeRessource:
db.session.delete(CoefRessource.query.filter_by(ressource=ressource, competence=self).first()) db.session.delete(CoefRessource.query.filter_by(ressource=ressource, competence=self).first())
db.session.commit() db.session.commit()
def export(self): def export(self):
result = dict(self.__dict__) result = dict(self.__dict__)

View File

@ -51,13 +51,21 @@ def Semestre(num):
for i, field in enumerate(form.ueform): for i, field in enumerate(form.ueform):
ue = models.Competence.query.filter_by(code=field.ue.data).first() ue = models.Competence.query.filter_by(code=field.ue.data).first()
ue.acs = field.acs.data ue.acs = field.acs.data
ue.updateCoefSAE(field.saes.data) # Fabrique la liste des Coefs qui ne doit pas être supprimé suite à un éventuel suppression d'un AC
ue.updateCoefRessource(field.ressources.data) 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: for coeffield in field.coef:
codeClass, code = coeffield.objetformation.data[1:-1].split() codeClass, code = coeffield.objetformation.data[1:-1].split()
model = getattr(models, codeClass) model = getattr(models, codeClass)
objetformation = model.query.filter_by(code=code).first() 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) objetformation.setCoef(coeffield.coef.data, ue)
db.session.commit() db.session.commit()
return redirect(url_for("Semestre", num=num)) return redirect(url_for("Semestre", num=num))