1
0
forked from ScoDoc/ScoDoc

Fix: filter out dups in sem resps or etapes

This commit is contained in:
Emmanuel Viennet 2021-02-18 08:08:29 +01:00
parent 7622cd1a7e
commit 8ea64acf07

View File

@ -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 !")