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' """fieldname: 'etapes' ou 'responsables'
valuename: 'etape_apo' ou 'responsable_id' valuename: 'etape_apo' ou 'responsable_id'
""" """
if not "etapes" in sem: if not fieldname in sem:
return return
# uniquify
values = set([str(x) for x in sem[fieldname]])
cnx = context.GetDBConnexion(autocommit=False) cnx = context.GetDBConnexion(autocommit=False)
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
tablename = "notes_formsemestre_" + fieldname 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", "DELETE from " + tablename + " where formsemestre_id = %(formsemestre_id)s",
{"formsemestre_id": sem["formsemestre_id"]}, {"formsemestre_id": sem["formsemestre_id"]},
) )
for item in sem[fieldname]: for item in values:
if item: if item:
cursor.execute( cursor.execute(
"INSERT INTO " "INSERT INTO "
@ -332,7 +335,7 @@ def _write_formsemestre_aux(context, sem, fieldname, valuename):
+ ") VALUES (%(formsemestre_id)s, %(" + ") VALUES (%(formsemestre_id)s, %("
+ valuename + valuename
+ ")s)", + ")s)",
{"formsemestre_id": sem["formsemestre_id"], valuename: str(item)}, {"formsemestre_id": sem["formsemestre_id"], valuename: item},
) )
except: except:
log("Warning: exception in write_formsemestre_aux !") log("Warning: exception in write_formsemestre_aux !")