forked from ScoDoc/ScoDoc
fix Module.set_ue_coef_dict
This commit is contained in:
parent
272de740e1
commit
2cca1e9bbd
@ -85,13 +85,27 @@ class Module(db.Model):
|
||||
Les coefs nuls (zéro) ne sont pas stockés: la relation est supprimée.
|
||||
"""
|
||||
ue_coefs = []
|
||||
changed = False
|
||||
for ue_id, coef in ue_coef_dict.items():
|
||||
ue = UniteEns.query.get(ue_id)
|
||||
if coef == 0.0:
|
||||
self.delete_ue_coef(ue)
|
||||
# Existant ?
|
||||
coefs = [c for c in self.ue_coefs if c.ue_id == ue_id]
|
||||
if coefs:
|
||||
ue_coef = coefs[0]
|
||||
if coef == 0.0: # supprime ce coef
|
||||
db.session.delete(ue_coef)
|
||||
changed = True
|
||||
elif coef != ue_coef.coef:
|
||||
ue_coef.coef = coef
|
||||
db.session.add(ue_coef)
|
||||
changed = True
|
||||
else:
|
||||
ue_coefs.append(ModuleUECoef(module=self, ue=ue, coef=coef))
|
||||
self.ue_coefs = ue_coefs
|
||||
# crée nouveau coef:
|
||||
if coef != 0.0:
|
||||
ue = UniteEns.query.get(ue_id)
|
||||
ue_coef = ModuleUECoef(module=self, ue=ue, coef=coef)
|
||||
self.ue_coefs.append(ue_coef)
|
||||
changed = True
|
||||
if changed:
|
||||
self.formation.invalidate_module_coefs()
|
||||
|
||||
def update_ue_coef_dict(self, ue_coef_dict: dict):
|
||||
|
Loading…
Reference in New Issue
Block a user