Compare commits
3 Commits
8758cb5238
...
985f7c7bcd
Author | SHA1 | Date |
---|---|---|
Pierre-antoine Comby | 985f7c7bcd | |
Pierre-antoine Comby | 72a752fd56 | |
Pierre-antoine Comby | 2996c9702f |
|
@ -82,13 +82,12 @@ class BulkCreateManager(object):
|
||||||
model_key = model_class._meta.label
|
model_key = model_class._meta.label
|
||||||
# check for mutli-table inheritance it happens
|
# check for mutli-table inheritance it happens
|
||||||
# if model_class is a grand-child of PolymorphicModel
|
# if model_class is a grand-child of PolymorphicModel
|
||||||
if model_class.__base__ is not PolymorphicModel and model_class.__base__.__base__ is PolymorphicModel:
|
if model_class.__base__.__base__ is PolymorphicModel:
|
||||||
self._commit(model_class.__base__)
|
self._commit(model_class.__base__)
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for obj in self._create_queues[model_key]:
|
for obj in self._create_queues[model_key]:
|
||||||
obj.save_base(raw=True)
|
obj.save_base(raw=True)
|
||||||
else:
|
else:
|
||||||
# ensure that parents models exists
|
|
||||||
model_class.objects.bulk_create(self._create_queues[model_key])
|
model_class.objects.bulk_create(self._create_queues[model_key])
|
||||||
self._create_queues[model_key] = []
|
self._create_queues[model_key] = []
|
||||||
|
|
||||||
|
|
|
@ -176,10 +176,10 @@ class Command(ImportCommand):
|
||||||
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
|
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
|
||||||
pk_alias = Alias.objects.order_by('-id').first().id + 1
|
pk_alias = Alias.objects.order_by('-id').first().id + 1
|
||||||
for idx, row in enumerate(cur):
|
for idx, row in enumerate(cur):
|
||||||
self.update_line(idx, n, row["alias"])
|
|
||||||
alias_name = row["alias"]
|
alias_name = row["alias"]
|
||||||
alias_name = (alias_name[:252] + '...') if len(alias_name) > 255 else alias_name
|
alias_name = (alias_name[:252] + '...') if len(alias_name) > 255 else alias_name
|
||||||
alias_norm = Alias.normalize(alias_name)
|
alias_norm = Alias.normalize(alias_name)
|
||||||
|
self.update_line(idx, n, alias_norm)
|
||||||
# clean pseudo (normalized pseudo must be unique)
|
# clean pseudo (normalized pseudo must be unique)
|
||||||
if alias_norm in ALIAS_SET:
|
if alias_norm in ALIAS_SET:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -22,10 +22,10 @@ class Command(ImportCommand):
|
||||||
|
|
||||||
@timed
|
@timed
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def import_activities(self, cur, chunk_size):
|
def import_activities(self, cur, chunk):
|
||||||
cur.execute("SELECT * FROM activites ORDER by id")
|
cur.execute("SELECT * FROM activites ORDER by id")
|
||||||
n = cur.rowcount
|
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
|
activity_type_id = ActivityType.objects.get(name="Pot").pk # Need to be fixed manually
|
||||||
kfet = Club.objects.get(name="Kfet")
|
kfet = Club.objects.get(name="Kfet")
|
||||||
pk_activity = 1
|
pk_activity = 1
|
||||||
|
@ -64,8 +64,8 @@ class Command(ImportCommand):
|
||||||
|
|
||||||
@timed
|
@timed
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def import_activities_entries(self, cur):
|
def import_guest(self, cur, chunk):
|
||||||
bulk_mgr = BulkCreateManager()
|
bulk_mgr = BulkCreateManager(chunk_size=chunk)
|
||||||
cur.execute("SELECT * FROM invites ORDER by id")
|
cur.execute("SELECT * FROM invites ORDER by id")
|
||||||
n = cur.rowcount
|
n = cur.rowcount
|
||||||
for idx, row in enumerate(cur):
|
for idx, row in enumerate(cur):
|
||||||
|
@ -79,6 +79,11 @@ class Command(ImportCommand):
|
||||||
}
|
}
|
||||||
bulk_mgr.add(Guest(**obj_dict))
|
bulk_mgr.add(Guest(**obj_dict))
|
||||||
bulk_mgr.done()
|
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")
|
cur.execute("SELECT * FROM entree_activites ORDER by id")
|
||||||
n = cur.rowcount
|
n = cur.rowcount
|
||||||
for idx, row in enumerate(cur):
|
for idx, row in enumerate(cur):
|
||||||
|
@ -86,8 +91,8 @@ class Command(ImportCommand):
|
||||||
obj_dict = {
|
obj_dict = {
|
||||||
"activity_id": MAP_ACTIVITY[row["activite"]],
|
"activity_id": MAP_ACTIVITY[row["activite"]],
|
||||||
"time": make_aware(row["heure_entree"]),
|
"time": make_aware(row["heure_entree"]),
|
||||||
"note_id": self.MAP_IDBDE[row["responsable"]] if row['est_invite'] else row["idbde"],
|
"note_id": self.MAP_IDBDE[row["responsable"] if row['est_invite'] else row["idbde"]],
|
||||||
"guest_id": row["idbde"] if row['est_invite'] else None,
|
"guest_id": self.MAP_IDBDE[row["idbde"]] if row['est_invite'] else None,
|
||||||
}
|
}
|
||||||
bulk_mgr.add(Entry(**obj_dict))
|
bulk_mgr.add(Entry(**obj_dict))
|
||||||
bulk_mgr.done()
|
bulk_mgr.done()
|
||||||
|
@ -102,4 +107,5 @@ class Command(ImportCommand):
|
||||||
if kwargs["map"]:
|
if kwargs["map"]:
|
||||||
self.load_map(kwargs["map"])
|
self.load_map(kwargs["map"])
|
||||||
self.import_activities(cur, kwargs["chunk"])
|
self.import_activities(cur, kwargs["chunk"])
|
||||||
self.import_activities_entries(cur)
|
self.import_guest(cur, kwargs["chunk"])
|
||||||
|
self.import_activities_entries(cur, kwargs["chunk"])
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
#!/usr/bin/sh
|
#!/usr/bin/sh
|
||||||
sudo -u postgres sh -c "dropdb note_db && psql -c 'CREATE DATABASE note_db OWNER note;'";
|
sudo -u postgres sh -c "dropdb note_db && psql -c 'CREATE DATABASE note_db OWNER note;'";
|
||||||
echo 'reset db';
|
echo 'reset db';
|
||||||
|
source "env/bin/activate"
|
||||||
|
./manage.py migrate
|
||||||
|
./manage.py loaddata initial
|
||||||
|
|
Loading…
Reference in New Issue