From 4fe61fdc5fd93a7fc8cd9b2acf644ff22125e0d7 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 9 Feb 2020 15:40:46 +0100 Subject: [PATCH] fix json file format test struct of json json file finish --- .../member/management/commands/import_nk15.py | 18 +- map_db.json | 199 ++++++++++++++---- 2 files changed, 168 insertions(+), 49 deletions(-) diff --git a/apps/member/management/commands/import_nk15.py b/apps/member/management/commands/import_nk15.py index 264262a9..1342cc09 100644 --- a/apps/member/management/commands/import_nk15.py +++ b/apps/member/management/commands/import_nk15.py @@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand from django.utils import timezone import psycopg2 as pg +import psycopg2.extras as pge import json @@ -19,12 +20,19 @@ class Command(BaseCommand): def handle(self, *args, **options): map_file= options.get("map",None) - with open(map_file,'rb') as f: + with open(map_file,'r') as f: map_dict = json.load(f); - #conn = pg.connect(database="nk15",user="nk_15") - #cur = conn.cursor() + conn = pg.connect(database="nk15",user="nk15_user") + cur = conn.cursor(cursor_factory = pge.DictCursor) - for old_table in map_dict: - print(old_table) + # Start with comptes table. + cur.execute("SELECT * FROM comptes ORDER BY -idbde LIMIT 5") + old_fields = [d[0] for d in cur.description] + + print(type(old_fields)) + for row in cur: + for old_field in old_fields: + + print(old_field,row[old_field]) diff --git a/map_db.json b/map_db.json index 5e8569f9..bd8b19c5 100644 --- a/map_db.json +++ b/map_db.json @@ -1,50 +1,161 @@ -[ - "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 +{ + "comptes":{ + "idbde":{ + "app":"note", + "model":"Note", + "field":"id" + }, + "type": null, + "pseudo":{ + "app":"member", + "model":"User", + "field":"username" + }, + "passwd":{ + "app":"member", + "model":"User", + "field":"password" + }, + "solde":{ + "app":"note", + "model":"Note", + "field":"solde" + }, + "nom":{ + "app":"member", + "model":"User", + "field":"first_name", + }, + "prenom":{ + "app":"member", + "model":"User", + "field":"last_name" + }, + "tel":{ + "app":"member", + "model":"Profile", + "field":"phone_number", + }, + "mail":{ + "app":"member", + "model":"User", + "field":"email" + }, + "adresse":{ + "app":"member", + "model":"Profile", + "field":"address" + }, + "fonction": null, + "normalien":{ + "app":"member", + "model":"Profile", + "field":"paid" + }, + "pbsante": null, + "droit": null, + "surdroit": null, + "supreme": null, + "bloque": null, + "last_adhesion": null, + "commentaire":null, + "last_negatif": null, + "deleted":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" + "transactions":{ + "id":{ + "app":"note", + "model":"Transaction", + "field":"" + },"Transaction.id", + "date":{ + "app":"note", + "model":"Transaction", + "field":"" + }"Transaction.created_at", + "type":{ + "app":"note", + "model":"Transaction", + "field":"" + } null, + "emetteur":{ + "app":"note", + "model":"Transaction", + "field":"id" + }, + "destinataire":{ + "app":"note", + "model":"Transaction", + "field":"destination_id" + }, + "quantite":{ + "app":"note", + "model":"Transaction", + "field":"quantity" + }, + "montant":{ + "app":"note", + "model":"Transaction", + "field":"amount" + }, + "description":{ + "app":"note", + "model":"Transaction", + "field":"reason" + }, + "valide":{ + "app":"note", + "model":"Transaction", + "field":"valid" + }, + "cantinvalidate": null, + "categorie":{ + "app":"note", + "model":"Transaction", + "field":"transaction_type" + } }, "boutons":{ - "id":"TransactionTemplate.id", - "label":"TransactionTemplate.name", - "montant":"TransactionTemplate.amount", - "destinataire":"TransactionTemplate.destination_id", - "categorie":null, - "affiche":null, - "description":null, - "consigne":null + "id":{ + "app":"note", + "model":"Transaction", + "field":"transaction_type" + }"TransactionTemplate.id", + "label":{ + "app":"note", + "model":"TransactionTemplate", + "field":"name" + }, + "montant":{ + "app":"note", + "model":"TransactionTemplate", + "field":"amount" + }, + "destinataire":{ + "app":"note", + "model":"TransactionTemplate", + "field":"destination_id" + }, + "categorie":null, + "affiche":null, + "description":null, + "consigne":null }, "aliases":{ - "id":"Alias.id", - "alias":"Alias.name", - "idbde":"Alias.note_id" + "id":{ + "app":"note", + "model":"Alias", + "field":"id" + }, + "alias":{ + "app":"note", + "model":"Alias", + "field":"name" + }, + "idbde":{ + "app":"note", + "model":"Alias", + "field":"note_id" + } } -] +}