1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2024-12-26 01:12:25 +00:00

refactor of Guest and Entry import

This commit is contained in:
Pierre-antoine Comby 2020-05-25 12:16:36 +02:00
parent 2996c9702f
commit 72a752fd56

View File

@ -22,10 +22,10 @@ class Command(ImportCommand):
@timed
@transaction.atomic
def import_activities(self, cur, chunk_size):
def import_activities(self, cur, chunk):
cur.execute("SELECT * FROM activites ORDER by id")
n = cur.rowcount
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
bulk_mgr = BulkCreateManager(chunk_size=chunk)
activity_type_id = ActivityType.objects.get(name="Pot").pk # Need to be fixed manually
kfet = Club.objects.get(name="Kfet")
pk_activity = 1
@ -64,8 +64,8 @@ class Command(ImportCommand):
@timed
@transaction.atomic
def import_activities_entries(self, cur):
bulk_mgr = BulkCreateManager()
def import_guest(self, cur, chunk):
bulk_mgr = BulkCreateManager(chunk_size=chunk)
cur.execute("SELECT * FROM invites ORDER by id")
n = cur.rowcount
for idx, row in enumerate(cur):
@ -79,6 +79,11 @@ class Command(ImportCommand):
}
bulk_mgr.add(Guest(**obj_dict))
bulk_mgr.done()
@timed
@transaction.atomic
def import_activities_entries(self, cur, chunk):
bulk_mgr = BulkCreateManager(chunk_size=chunk)
cur.execute("SELECT * FROM entree_activites ORDER by id")
n = cur.rowcount
for idx, row in enumerate(cur):
@ -86,8 +91,8 @@ class Command(ImportCommand):
obj_dict = {
"activity_id": MAP_ACTIVITY[row["activite"]],
"time": make_aware(row["heure_entree"]),
"note_id": self.MAP_IDBDE[row["responsable"]] if row['est_invite'] else row["idbde"],
"guest_id": row["idbde"] if row['est_invite'] else None,
"note_id": self.MAP_IDBDE[row["responsable"] if row['est_invite'] else row["idbde"]],
"guest_id": self.MAP_IDBDE[row["idbde"]] if row['est_invite'] else None,
}
bulk_mgr.add(Entry(**obj_dict))
bulk_mgr.done()
@ -102,4 +107,5 @@ class Command(ImportCommand):
if kwargs["map"]:
self.load_map(kwargs["map"])
self.import_activities(cur, kwargs["chunk"])
self.import_activities_entries(cur)
self.import_guest(cur, kwargs["chunk"])
self.import_activities_entries(cur, kwargs["chunk"])