fix integrity error

This commit is contained in:
Pierre-antoine Comby 2020-03-09 19:00:19 +01:00
parent a088c6baea
commit 123466cfa9
1 changed files with 23 additions and 21 deletions

View File

@ -8,6 +8,7 @@ import psycopg2.extras as pge
from django.db import transaction from django.db import transaction
import collections import collections
from datetime import timedelta
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.timezone import make_aware from django.utils.timezone import make_aware
@ -28,6 +29,10 @@ TODO: import activite
TODO: import ... TODO: import ...
""" """
M_DURATION = timedelta(days=396)
M_START = timedelta(days=213)
M_END = timedelta(days=273)
@transaction.atomic @transaction.atomic
def import_special(cur): def import_special(cur):
cur.execute("SELECT * FROM comptes WHERE idbde <0 ORDER BY idbde;") cur.execute("SELECT * FROM comptes WHERE idbde <0 ORDER BY idbde;")
@ -45,17 +50,17 @@ def import_special(cur):
clubBde, c = Club.objects.get_or_create(pk = 1, clubBde, c = Club.objects.get_or_create(pk = 1,
name = "Bde", name = "Bde",
email = "bureau.bde@lists.crans.org", email = "bureau.bde@lists.crans.org",
membership_duration = "396 00:00:00", membership_duration = M_DURATION,
membership_start = "213 00:00:00", membership_start = M_START,
membership_end = "273 00:00:00", membership_end = M_END,
membership_fee = 5, membership_fee = 5,
) )
clubKfet, c = Club.objects.get_or_create(pk = 2, clubKfet, c = Club.objects.get_or_create(pk = 2,
name = "Kfet", name = "Kfet",
email = "tresorerie.bde@lists.crans.org", email = "tresorerie.bde@lists.crans.org",
membership_duration = "396 00:00:00", membership_duration = M_DURATION,
membership_start = "213 00:00:00", membership_start = M_START,
membership_end = "273 00:00:00", membership_end = M_END,
membership_fee = 35, membership_fee = 35,
) )
clubBde.save() clubBde.save()
@ -93,15 +98,12 @@ def import_comptes(cur,map_idbde):
user = User.objects.create(**obj_dict) user = User.objects.create(**obj_dict)
else: else:
raise(e) raise(e)
else: # profile and note created via signal.
pass profile = user.profile
obj_dict ={ profile.phone_number = row["tel"]
"phone_number": row["tel"], profile.address = row["adresse"]
"address": row["adresse"], profile.paid = row["normalien"]
"paid": row["normalien"],
"user": user,
}
profile = Profile.objects.create(**obj_dict)
note = user.note note = user.note
date = row.get("last_negatif",None) date = row.get("last_negatif",None)
if date != None: if date != None:
@ -113,9 +115,9 @@ def import_comptes(cur,map_idbde):
"pk":pkclub, "pk":pkclub,
"name": row["pseudo"], "name": row["pseudo"],
"email": row["mail"], "email": row["mail"],
"membership_duration": "396 00:00:00", "membership_duration": M_DURATION,
"membership_start": "213 00:00:00", "membership_start": M_START,
"membership_end": "273 00:00:00", "membership_end": M_END,
"membership_fee": 0, "membership_fee": 0,
} }
club,c = Club.objects.get_or_create(**obj_dict) club,c = Club.objects.get_or_create(**obj_dict)
@ -125,7 +127,7 @@ def import_comptes(cur,map_idbde):
obj_list = [club,note] obj_list = [club,note]
for obj in obj_list: for obj in obj_list:
obj.save() obj.save()
map_idbde[row["idbde"]] = note.pk map_idbde[row["idbde"]] = note.pk
return map_idbde return map_idbde
@ -184,9 +186,9 @@ def import_transaction(cur, map_idbde):
transac = TemplateTransaction.objects.create(**obj_dict) transac = TemplateTransaction.objects.create(**obj_dict)
transac.save() transac.save()
elif row["type"] == "adhésion": elif row["type"] == "adhésion":
print("adhesion not supported yet")
else: else:
print("other type not supported yet")
@transaction.atomic @transaction.atomic