diff --git a/management/commands/import_nk15.py b/management/commands/import_nk15.py index e79f676..7b8e7de 100644 --- a/management/commands/import_nk15.py +++ b/management/commands/import_nk15.py @@ -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)