Fix: delete objet de formation+AC

This commit is contained in:
Éric Li 2021-06-15 12:07:27 +02:00
parent 932fdfddef
commit 31d0aaf29b
2 changed files with 10 additions and 7 deletions

View File

@ -88,8 +88,8 @@ class CoefSAE(db.Model):
competence_code = db.Column(db.String(32), db.ForeignKey("competence.code"), primary_key=True) 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) sae_code = db.Column(db.String(32), db.ForeignKey("SAE.code"), primary_key=True)
coef = db.Column(db.String(2)) coef = db.Column(db.String(2))
competence = db.relationship("Competence", lazy=False, backref=db.backref("saes")) 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")) sae = db.relationship("SAE", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan"))
def export(self): def export(self):
result = dict(self.__dict__) 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) 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) ressource_code = db.Column(db.String(32), db.ForeignKey("ressource.code"), primary_key=True)
coef = db.Column(db.String(2)) coef = db.Column(db.String(2))
competence = db.relationship("Competence", lazy=False, backref=db.backref("ressources")) 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")) ressource = db.relationship("Ressource", lazy=False, backref=db.backref("competences", cascade="save-update, merge, delete, delete-orphan"))
def export(self): def export(self):
result = dict(self.__dict__) result = dict(self.__dict__)

View File

@ -47,9 +47,12 @@ def Semestre(num):
form.ueform.__getitem__(i).ressources.query=queryRessource form.ueform.__getitem__(i).ressources.query=queryRessource
if not form.update.data: if not form.update.data:
for coefsae in ue.saes: 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: 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 # Appuie sur Update
if form.update.data: if form.update.data:
semestre.ues = [ue for ue in form.ues.data] semestre.ues = [ue for ue in form.ues.data]
@ -57,7 +60,7 @@ 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
# 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 = [] querySAE = []
queryRessource = [] queryRessource = []
for ac in ue.acs: for ac in ue.acs: