mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-26 01:12:25 +00:00
Import the creation date of the accounts
This commit is contained in:
parent
9dcb25723e
commit
ceb7063f17
@ -19,7 +19,7 @@ from member.models import Club, Profile
|
||||
from ._import_utils import ImportCommand, BulkCreateManager, timed
|
||||
|
||||
M_DURATION = 396
|
||||
M_START = datetime.date(2019, 8, 31)
|
||||
M_START = datetime.date(2019, 8, 1)
|
||||
M_END = datetime.date(2020, 9, 30)
|
||||
|
||||
MAP_IDBDE = {
|
||||
@ -60,6 +60,13 @@ class Command(ImportCommand):
|
||||
Every Model has to be manually created, and no magic `.save()`
|
||||
function is being called.
|
||||
"""
|
||||
# Get promotion and date of creation of the account
|
||||
cur.execute("SELECT idbde, MIN(date) AS created_at, MIN(annee) AS promo FROM adhesions"
|
||||
" GROUP BY idbde ORDER BY promo, created_at;")
|
||||
MAP_IDBDE_PROMOTION = {}
|
||||
for row in cur:
|
||||
MAP_IDBDE_PROMOTION[row["idbde"]] = row
|
||||
|
||||
cur.execute("SELECT * FROM comptes WHERE idbde > 0 ORDER BY idbde;")
|
||||
pk_club = 3
|
||||
pk_user = 1
|
||||
@ -84,7 +91,6 @@ class Command(ImportCommand):
|
||||
"last_negative": None,
|
||||
"is_active": True,
|
||||
"display_image": "pic/default.png",
|
||||
"created_at": now()
|
||||
}
|
||||
if row["last_negatif"] is not None:
|
||||
note_dict["last_negative"] = make_aware(row["last_negatif"])
|
||||
@ -95,6 +101,11 @@ class Command(ImportCommand):
|
||||
else:
|
||||
passwd_nk15 = ''
|
||||
|
||||
if row["idbde"] not in MAP_IDBDE_PROMOTION:
|
||||
# NK12 bug. Applying default values
|
||||
MAP_IDBDE_PROMOTION[row["idbde"]] = {"promo": 2014,
|
||||
"created_at": datetime.datetime(2014, 9, 1, 0, 0, 0)}
|
||||
|
||||
obj_dict = {
|
||||
"pk": pk_user,
|
||||
"username": row["pseudo"],
|
||||
@ -112,7 +123,9 @@ class Command(ImportCommand):
|
||||
"paid": row['normalien'],
|
||||
"registration_valid": True,
|
||||
"email_confirmed": True,
|
||||
"promotion": MAP_IDBDE_PROMOTION[row["idbde"]]["promo"],
|
||||
}
|
||||
note_dict["created_at"] = make_aware(MAP_IDBDE_PROMOTION[row["idbde"]]["created_at"])
|
||||
note_dict["polymorphic_ctype"] = note_user_type
|
||||
note_user_dict = {
|
||||
"pk": pk_note,
|
||||
@ -138,6 +151,7 @@ class Command(ImportCommand):
|
||||
"pk": pk_club,
|
||||
"name": row["pseudo"],
|
||||
"email": row["mail"],
|
||||
"parent_club": 1, # All clubs depends on BDE by default
|
||||
"membership_duration": M_DURATION,
|
||||
"membership_start": M_START,
|
||||
"membership_end": M_END,
|
||||
@ -146,7 +160,7 @@ class Command(ImportCommand):
|
||||
}
|
||||
note_club_dict = {
|
||||
"pk": pk_note,
|
||||
"club_id": pk_club,
|
||||
"club_id": pk_club
|
||||
}
|
||||
alias_dict = {
|
||||
"pk": pk_note,
|
||||
@ -154,16 +168,18 @@ class Command(ImportCommand):
|
||||
"normalized_name": Alias.normalize(pseudo),
|
||||
"note_id": pk_note
|
||||
}
|
||||
note_dict["created_at"] = make_aware(row["previous_report_date"]) # Not perfect, but good approximation
|
||||
note_dict["polymorphic_ctype"] = note_club_type
|
||||
bulk_mgr.add(Club(**obj_dict),
|
||||
Note(**note_dict),
|
||||
NoteClub(**note_club_dict),
|
||||
Alias(**alias_dict))
|
||||
#bulk_mgr.add(Club(**obj_dict),
|
||||
# Note(**note_dict),
|
||||
# NoteClub(**note_club_dict),
|
||||
# Alias(**alias_dict))
|
||||
pk_club += 1
|
||||
# row import completed
|
||||
MAP_IDBDE[row["idbde"]] = pk_note
|
||||
pk_note += 1
|
||||
bulk_mgr.done()
|
||||
exit(0)
|
||||
|
||||
@timed
|
||||
def import_alias(self, cur, chunk_size):
|
||||
|
Loading…
Reference in New Issue
Block a user