forked from ScoDoc/ScoDoc
ignore inscriptions répétées
This commit is contained in:
parent
76af0eb166
commit
651f111839
@ -88,7 +88,15 @@ def SimpleDictFetch(query, args, cursor=None):
|
|||||||
return cursor.dictfetchall()
|
return cursor.dictfetchall()
|
||||||
|
|
||||||
|
|
||||||
def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1, return_id=True):
|
def DBInsertDict(
|
||||||
|
cnx,
|
||||||
|
table,
|
||||||
|
vals,
|
||||||
|
commit=0,
|
||||||
|
convert_empty_to_nulls=1,
|
||||||
|
return_id=True,
|
||||||
|
ignore_conflicts=False,
|
||||||
|
):
|
||||||
"""insert into table values in dict 'vals'
|
"""insert into table values in dict 'vals'
|
||||||
Return: id de l'object créé
|
Return: id de l'object créé
|
||||||
"""
|
"""
|
||||||
@ -103,13 +111,18 @@ def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1, return_id
|
|||||||
fmt = ",".join(["%%(%s)s" % col for col in cols])
|
fmt = ",".join(["%%(%s)s" % col for col in cols])
|
||||||
# print 'insert into %s (%s) values (%s)' % (table,colnames,fmt)
|
# print 'insert into %s (%s) values (%s)' % (table,colnames,fmt)
|
||||||
oid = None
|
oid = None
|
||||||
|
if ignore_conflicts:
|
||||||
|
ignore = " ON CONFLICT DO NOTHING"
|
||||||
|
else:
|
||||||
|
ignore = ""
|
||||||
try:
|
try:
|
||||||
if vals:
|
if vals:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"insert into %s (%s) values (%s)" % (table, colnames, fmt), vals
|
"insert into %s (%s) values (%s)%s" % (table, colnames, fmt, ignore),
|
||||||
|
vals,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
cursor.execute("insert into %s default values" % table)
|
cursor.execute("insert into %s default values%s" % (table, ignore))
|
||||||
if return_id:
|
if return_id:
|
||||||
cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé
|
cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé
|
||||||
oid = cursor.fetchone()[0]
|
oid = cursor.fetchone()[0]
|
||||||
@ -291,6 +304,7 @@ class EditableTable(object):
|
|||||||
fields_creators={}, # { field : [ sql_command_to_create_it ] }
|
fields_creators={}, # { field : [ sql_command_to_create_it ] }
|
||||||
filter_nulls=True, # dont allow to set fields to null
|
filter_nulls=True, # dont allow to set fields to null
|
||||||
filter_dept=False, # ajoute selection sur g.scodoc_dept_id
|
filter_dept=False, # ajoute selection sur g.scodoc_dept_id
|
||||||
|
insert_ignore_conflicts=False,
|
||||||
):
|
):
|
||||||
self.table_name = table_name
|
self.table_name = table_name
|
||||||
self.id_name = id_name
|
self.id_name = id_name
|
||||||
@ -311,6 +325,7 @@ class EditableTable(object):
|
|||||||
self.filter_nulls = filter_nulls
|
self.filter_nulls = filter_nulls
|
||||||
self.filter_dept = filter_dept
|
self.filter_dept = filter_dept
|
||||||
self.sql_default_values = None
|
self.sql_default_values = None
|
||||||
|
self.insert_ignore_conflicts = insert_ignore_conflicts
|
||||||
|
|
||||||
def create(self, cnx, args):
|
def create(self, cnx, args):
|
||||||
"create object in table"
|
"create object in table"
|
||||||
@ -336,6 +351,7 @@ class EditableTable(object):
|
|||||||
vals,
|
vals,
|
||||||
commit=True,
|
commit=True,
|
||||||
return_id=(self.id_name is not None),
|
return_id=(self.id_name is not None),
|
||||||
|
ignore_conflicts=self.insert_ignore_conflicts,
|
||||||
)
|
)
|
||||||
return new_id
|
return new_id
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ _formsemestre_inscriptionEditor = ndb.EditableTable(
|
|||||||
"formsemestre_inscription_id",
|
"formsemestre_inscription_id",
|
||||||
("formsemestre_inscription_id", "etudid", "formsemestre_id", "etat", "etape"),
|
("formsemestre_inscription_id", "etudid", "formsemestre_id", "etat", "etape"),
|
||||||
sortkey="formsemestre_id",
|
sortkey="formsemestre_id",
|
||||||
|
insert_ignore_conflicts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user