From c843bfd4781fab7fa5f359749e0e461db68052bc Mon Sep 17 00:00:00 2001 From: Nekori Date: Thu, 10 Jun 2021 17:05:57 +0200 Subject: [PATCH] Fix: AC suppr -> Coef de l'AC suppr --- app/models.py | 30 ++++++++++++++++-------------- app/routes.py | 14 +++++++++++--- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/models.py b/app/models.py index f288e14..39bb8c7 100644 --- a/app/models.py +++ b/app/models.py @@ -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__) diff --git a/app/routes.py b/app/routes.py index 8380f3c..90248f5 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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))