diff --git a/app/models.py b/app/models.py index 780d04f..8069b57 100644 --- a/app/models.py +++ b/app/models.py @@ -88,8 +88,8 @@ class CoefSAE(db.Model): competence_code = db.Column(db.String(32), db.ForeignKey("competence.code"), primary_key=True) sae_code = db.Column(db.String(32), db.ForeignKey("SAE.code"), primary_key=True) coef = db.Column(db.String(2)) - competence = db.relationship("Competence", lazy=False, backref=db.backref("saes")) - sae = db.relationship("SAE", lazy=False, backref=db.backref("competences")) + competence = db.relationship("Competence", lazy=False, backref=db.backref("saes", cascade="save-update, merge, delete, delete-orphan")) + sae = db.relationship("SAE", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan")) def export(self): result = dict(self.__dict__) @@ -100,8 +100,8 @@ class CoefRessource(db.Model): competence_code = db.Column(db.String(32), db.ForeignKey("competence.code"), primary_key=True) ressource_code = db.Column(db.String(32), db.ForeignKey("ressource.code"), primary_key=True) coef = db.Column(db.String(2)) - competence = db.relationship("Competence", lazy=False, backref=db.backref("ressources")) - ressource = db.relationship("Ressource", lazy=False, backref=db.backref("competences")) + competence = db.relationship("Competence", lazy=False, backref=db.backref("ressources", cascade="save-update, merge, delete, delete-orphan")) + ressource = db.relationship("Ressource", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan")) def export(self): result = dict(self.__dict__) diff --git a/app/routes.py b/app/routes.py index 4df68a0..0a1aeb4 100644 --- a/app/routes.py +++ b/app/routes.py @@ -47,9 +47,12 @@ def Semestre(num): 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}) + if coefsae.sae in querySAE: form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefsae.sae}) + else: db.session.delete(coefsae) for coefressource in ue.ressources: - form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefressource.ressource}) + if coefressource.ressource in queryRessource: form.ueform.__getitem__(i).coef.append_entry(data={"objetformation": coefressource.ressource}) + else: db.session.delete(coefressource) + db.session.commit() # Appuie sur Update if form.update.data: semestre.ues = [ue for ue in form.ues.data] @@ -57,7 +60,7 @@ 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 - # Fabrique la liste des Coefs qui ne doit pas être supprimé suite à un éventuel suppression d'un AC + # Fabrique la liste des Coefs qui ne doit pas être supprimé suite à un éventuel désélection d'un AC querySAE = [] queryRessource = [] for ac in ue.acs: