1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2024-12-27 01:42:24 +00:00

import of alias and buttons works again

This commit is contained in:
Pierre-antoine Comby 2020-03-14 11:41:08 +01:00
parent 123466cfa9
commit be8aa44eb6

View File

@ -136,6 +136,8 @@ def import_boutons(cur,map_idbde):
cur.execute("SELECT * FROM boutons;")
for row in cur:
cat, created = TemplateCategory.objects.get_or_create(name=row["categorie"])
if created:
cat.save()
obj_dict = {
"pk": row["id"],
"name": row["label"],
@ -149,15 +151,15 @@ def import_boutons(cur,map_idbde):
with transaction.atomic(): # required for error management
button = TransactionTemplate.objects.create(**obj_dict)
except IntegrityError as e:
# button with the same name is not possible in NK20.
if "unique" in e.args[0]:
qs = Club.objects.filter(note__id=map_idbde[row["destinataire"]]).values('name')
note_name = qs[0]["name"]
obj_dict["name"] = ' '.join([obj_dict["name"],note_name])
#rename button name
obj_dict["name"] ="{} {}".format(obj_dict["name"],note_name)
button = TransactionTemplate.objects.create(**obj_dict)
else:
raise(e)
if created:
cat.save()
button.save()
@ -200,12 +202,15 @@ def import_aliases(cur,map_idbde):
obj_dict = {
"note_id":map_idbde[row["idbde"]],
"name":alias_name_good,
"normalized_name":Alias.normalize(alias_name_good)
}
try:
with transaction.atomic():
alias = Alias.objects.create(**obj_dict)
alias, created = Alias.objects.get_or_create(**obj_dict)
print(alias)
except IntegrityError as e:
if "unique" in e.args[0]:
print("error, {}".format(alias))
continue
else:
raise(e)