From 8ea64acf07cf73af49f56cfd003d0d00ad56c1c4 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 18 Feb 2021 08:08:29 +0100 Subject: [PATCH] Fix: filter out dups in sem resps or etapes --- sco_formsemestre.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sco_formsemestre.py b/sco_formsemestre.py index 8b13e91a..2a5db9c1 100644 --- a/sco_formsemestre.py +++ b/sco_formsemestre.py @@ -312,8 +312,11 @@ def _write_formsemestre_aux(context, sem, fieldname, valuename): """fieldname: 'etapes' ou 'responsables' valuename: 'etape_apo' ou 'responsable_id' """ - if not "etapes" in sem: + if not fieldname in sem: return + # uniquify + values = set([str(x) for x in sem[fieldname]]) + cnx = context.GetDBConnexion(autocommit=False) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) tablename = "notes_formsemestre_" + fieldname @@ -322,7 +325,7 @@ def _write_formsemestre_aux(context, sem, fieldname, valuename): "DELETE from " + tablename + " where formsemestre_id = %(formsemestre_id)s", {"formsemestre_id": sem["formsemestre_id"]}, ) - for item in sem[fieldname]: + for item in values: if item: cursor.execute( "INSERT INTO " @@ -332,7 +335,7 @@ def _write_formsemestre_aux(context, sem, fieldname, valuename): + ") VALUES (%(formsemestre_id)s, %(" + valuename + ")s)", - {"formsemestre_id": sem["formsemestre_id"], valuename: str(item)}, + {"formsemestre_id": sem["formsemestre_id"], valuename: item}, ) except: log("Warning: exception in write_formsemestre_aux !")