add aliases import

This commit is contained in:
Pierre-antoine Comby 2020-02-23 21:11:42 +01:00
parent e850c5755b
commit 9207c5cdec
1 changed files with 26 additions and 1 deletions

View File

@ -152,6 +152,7 @@ def import_boutons(cur,map_idbde):
cat.save()
button.save()
@transaction.atomic
def import_transaction(cur, map_idbde):
cur.execute("SELECT * FROM transactions;")
@ -160,6 +161,26 @@ def import_transaction(cur, map_idbde):
"pk":row["id"],
}
@transaction.atomic
def import_aliases(cur,map_idbde):
cur.execute("SELECT * FROM aliases ORDER by id")
for row in cur:
alias_name = row["alias"]
alias_name_good = (alias_name[:252]+'...') if len(alias_name) > 255 else alias_name
obj_dict = {
"note_id":map_idbde[row["idbde"]],
"name":alias_name_good,
}
try:
with transaction.atomic():
alias = Alias.objects.create(**obj_dict)
except IntegrityError as e:
if "unique" in e.args[0]:
continue
else:
raise(e)
alias.save()
class Command(BaseCommand):
"""
@ -171,6 +192,7 @@ class Command(BaseCommand):
parser.add_argument('-c', '--comptes', action = 'store_true')
parser.add_argument('-b', '--boutons', action = 'store_true')
parser.add_argument('-t', '--transactions', action = 'store_true')
parser.add_argument('-a', '--aliases', action = 'store_true')
def handle(self, *args, **kwargs):
conn = pg.connect(database="nk15",user="nk15_user")
@ -189,3 +211,6 @@ class Command(BaseCommand):
print("boutons table imported")
if kwargs["transactions"]:
import_transaction(cur)
if kwargs["aliases"]:
import_aliases(cur,map_idbde)
print("aliases imported")