import of alias and buttons works again
This commit is contained in:
parent
123466cfa9
commit
be8aa44eb6
|
@ -136,6 +136,8 @@ def import_boutons(cur,map_idbde):
|
||||||
cur.execute("SELECT * FROM boutons;")
|
cur.execute("SELECT * FROM boutons;")
|
||||||
for row in cur:
|
for row in cur:
|
||||||
cat, created = TemplateCategory.objects.get_or_create(name=row["categorie"])
|
cat, created = TemplateCategory.objects.get_or_create(name=row["categorie"])
|
||||||
|
if created:
|
||||||
|
cat.save()
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
"pk": row["id"],
|
"pk": row["id"],
|
||||||
"name": row["label"],
|
"name": row["label"],
|
||||||
|
@ -149,15 +151,15 @@ def import_boutons(cur,map_idbde):
|
||||||
with transaction.atomic(): # required for error management
|
with transaction.atomic(): # required for error management
|
||||||
button = TransactionTemplate.objects.create(**obj_dict)
|
button = TransactionTemplate.objects.create(**obj_dict)
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
|
# button with the same name is not possible in NK20.
|
||||||
if "unique" in e.args[0]:
|
if "unique" in e.args[0]:
|
||||||
qs = Club.objects.filter(note__id=map_idbde[row["destinataire"]]).values('name')
|
qs = Club.objects.filter(note__id=map_idbde[row["destinataire"]]).values('name')
|
||||||
note_name = qs[0]["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)
|
button = TransactionTemplate.objects.create(**obj_dict)
|
||||||
else:
|
else:
|
||||||
raise(e)
|
raise(e)
|
||||||
if created:
|
|
||||||
cat.save()
|
|
||||||
button.save()
|
button.save()
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,12 +202,15 @@ def import_aliases(cur,map_idbde):
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
"note_id":map_idbde[row["idbde"]],
|
"note_id":map_idbde[row["idbde"]],
|
||||||
"name":alias_name_good,
|
"name":alias_name_good,
|
||||||
|
"normalized_name":Alias.normalize(alias_name_good)
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
alias = Alias.objects.create(**obj_dict)
|
alias, created = Alias.objects.get_or_create(**obj_dict)
|
||||||
|
print(alias)
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
if "unique" in e.args[0]:
|
if "unique" in e.args[0]:
|
||||||
|
print("error, {}".format(alias))
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise(e)
|
raise(e)
|
||||||
|
|
Loading…
Reference in New Issue