From 71a88e84f7f5833b0ef3c19f26be435aed56626f Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 7 Feb 2020 22:23:37 +0100 Subject: [PATCH] initiate import command --- apps/member/management/__init__.py | 0 apps/member/management/commands/__init__.py | 0 .../member/management/commands/import_nk15.py | 30 +++++++++++ map_db.json | 50 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 apps/member/management/__init__.py create mode 100644 apps/member/management/commands/__init__.py create mode 100644 apps/member/management/commands/import_nk15.py create mode 100644 map_db.json diff --git a/apps/member/management/__init__.py b/apps/member/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/member/management/commands/__init__.py b/apps/member/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/member/management/commands/import_nk15.py b/apps/member/management/commands/import_nk15.py new file mode 100644 index 00000000..264262a9 --- /dev/null +++ b/apps/member/management/commands/import_nk15.py @@ -0,0 +1,30 @@ +#!/usr/env/bin python3 + +from django.core.management.base import BaseCommand +from django.utils import timezone +import psycopg2 as pg +import json + + +class Command(BaseCommand): + """ + Command for importing the database of NK15. + Need to be run by a user with a registered role in postgres for the database nk15. + """ + help = 'Displays current time' + + def add_arguments(self,parser): + parser.add_argument("--map",type=str,help="json mapping of table header to field models") + + + def handle(self, *args, **options): + map_file= options.get("map",None) + with open(map_file,'rb') as f: + map_dict = json.load(f); + + #conn = pg.connect(database="nk15",user="nk_15") + #cur = conn.cursor() + + for old_table in map_dict: + print(old_table) + diff --git a/map_db.json b/map_db.json new file mode 100644 index 00000000..5e8569f9 --- /dev/null +++ b/map_db.json @@ -0,0 +1,50 @@ +[ + "comptes": { + "idbde":"Note.id", + "type": null, + "pseudo":"User.username", + "passwd":"User.password", + "solde":"Note.solde", + "nom":"User.first_name", + "prenom":"User.last_name", + "tel":"Profile.phone_number", + "mail":"User.email", + "adresse":"Profile.address", + "fonction": null, + "normalien": "Profile.paid", + "pbsante": null, + "droit": null, + "surdroit": null, + "supreme": null, + "bloque": null, + "last_adhesion": null + }, + "transaction":{ + "id":"Transaction.id", + "date":"Transaction.created_at", + "type": null, + "emetteur":"Transaction.source_id", + "destinataire":"Transaction.destination_id", + "quantite":"Transaction.quantity", + "montant":"Transaction.amount", + "description":"Transaction.reason", + "valide":"Transaction.valid", + "cantinvalidate": null, + "categorie":"Transaction.transaction_type" + }, + "boutons":{ + "id":"TransactionTemplate.id", + "label":"TransactionTemplate.name", + "montant":"TransactionTemplate.amount", + "destinataire":"TransactionTemplate.destination_id", + "categorie":null, + "affiche":null, + "description":null, + "consigne":null + }, + "aliases":{ + "id":"Alias.id", + "alias":"Alias.name", + "idbde":"Alias.note_id" + } +]