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