fix json file format

test struct of json

json file finish
This commit is contained in:
Pierre-antoine Comby 2020-02-09 15:40:46 +01:00
parent 71a88e84f7
commit 4fe61fdc5f
2 changed files with 168 additions and 49 deletions

View File

@ -3,6 +3,7 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils import timezone from django.utils import timezone
import psycopg2 as pg import psycopg2 as pg
import psycopg2.extras as pge
import json import json
@ -19,12 +20,19 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
map_file= options.get("map",None) 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); map_dict = json.load(f);
#conn = pg.connect(database="nk15",user="nk_15") conn = pg.connect(database="nk15",user="nk15_user")
#cur = conn.cursor() cur = conn.cursor(cursor_factory = pge.DictCursor)
for old_table in map_dict: # Start with comptes table.
print(old_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])

View File

@ -1,50 +1,161 @@
[ {
"comptes":{ "comptes":{
"idbde":"Note.id", "idbde":{
"app":"note",
"model":"Note",
"field":"id"
},
"type": null, "type": null,
"pseudo":"User.username", "pseudo":{
"passwd":"User.password", "app":"member",
"solde":"Note.solde", "model":"User",
"nom":"User.first_name", "field":"username"
"prenom":"User.last_name", },
"tel":"Profile.phone_number", "passwd":{
"mail":"User.email", "app":"member",
"adresse":"Profile.address", "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, "fonction": null,
"normalien": "Profile.paid", "normalien":{
"app":"member",
"model":"Profile",
"field":"paid"
},
"pbsante": null, "pbsante": null,
"droit": null, "droit": null,
"surdroit": null, "surdroit": null,
"supreme": null, "supreme": null,
"bloque": null, "bloque": null,
"last_adhesion": null "last_adhesion": null,
"commentaire":null,
"last_negatif": null,
"deleted":null
},
"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"
}, },
"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, "cantinvalidate": null,
"categorie":"Transaction.transaction_type" "categorie":{
"app":"note",
"model":"Transaction",
"field":"transaction_type"
}
}, },
"boutons":{ "boutons":{
"id":"TransactionTemplate.id", "id":{
"label":"TransactionTemplate.name", "app":"note",
"montant":"TransactionTemplate.amount", "model":"Transaction",
"destinataire":"TransactionTemplate.destination_id", "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, "categorie":null,
"affiche":null, "affiche":null,
"description":null, "description":null,
"consigne":null "consigne":null
}, },
"aliases":{ "aliases":{
"id":"Alias.id", "id":{
"alias":"Alias.name", "app":"note",
"idbde":"Alias.note_id" "model":"Alias",
"field":"id"
},
"alias":{
"app":"note",
"model":"Alias",
"field":"name"
},
"idbde":{
"app":"note",
"model":"Alias",
"field":"note_id"
}
}
} }
]