Compare commits

..

No commits in common. "6cfae5fd69deb8beccb342cb589c6d8c594cf1b8" and "dc1daf0a2ddd6a74be0f2c06473a6ad16596d10b" have entirely different histories.

4 changed files with 20 additions and 48 deletions

View File

@ -44,14 +44,14 @@ class ImportCommand(BaseCommand):
n = str(n) n = str(n)
total = str(total) total = str(total)
n.rjust(len(total)) n.rjust(len(total))
print(f"\r ({n}/{total}) {content:16.16}", end="") print(f"\r ({n}/{total}) {content:10.10}", end="")
def create_parser(self, prog_name, subcommand, **kwargs): def create_parser(self, prog_name, subcommand, **kwargs):
parser = super().create_parser(prog_name, subcommand, **kwargs) parser = super().create_parser(prog_name, subcommand, **kwargs)
parser.add_argument('--nk15db', action='store', default='nk15', help='NK15 database name') parser.add_argument('--nk15db', action='store', default='nk15', help='NK15 database name')
parser.add_argument('--nk15user', action='store', default='nk15_user', help='NK15 database owner') parser.add_argument('--nk15user', action='store', default='nk15_user', help='NK15 database owner')
parser.add_argument('-s', '--save', default='map.json', action='store', help="save mapping of idbde") parser.add_argument('-s', '--save', action='store', help="save mapping of idbde")
parser.add_argument('-m', '--map', default='map.json', action='store', help="import mapping of idbde") parser.add_argument('-m', '--map', action='store', help="import mapping of idbde")
parser.add_argument('-c', '--chunk', type=int, default=100, help="chunk size for bulk_create") parser.add_argument('-c', '--chunk', type=int, default=100, help="chunk size for bulk_create")
return parser return parser

View File

@ -10,7 +10,7 @@ from django.db import transaction
from activity.models import ActivityType, Activity, Guest, Entry from activity.models import ActivityType, Activity, Guest, Entry
from member.models import Club from member.models import Club
from note.models import Note, NoteUser from note.models import Note
from ._import_utils import ImportCommand, BulkCreateManager, timed from ._import_utils import ImportCommand, BulkCreateManager, timed
MAP_ACTIVITY = dict() MAP_ACTIVITY = dict()
@ -19,13 +19,9 @@ CLUB_RELOU = [
0, # BDE 0, # BDE
4771, # Kataclist 4771, # Kataclist
5162, # Assurance BDE ?! 5162, # Assurance BDE ?!
5164, # S & L 5164, #S & L
625, # Aspique 625, #Aspique
5154, # Frekens 5154, #Frekens
3944, # DiskJok[ENS]
5153, # Monopo[list]
2351, # JdRM
2365, # Pot Vieux
] ]
class Command(ImportCommand): class Command(ImportCommand):
@ -44,13 +40,11 @@ class Command(ImportCommand):
pk_activity = 1 pk_activity = 1
for idx, row in enumerate(cur): for idx, row in enumerate(cur):
self.update_line(idx, n, row["titre"]) self.update_line(idx, n, row["titre"])
if row["responsable"] in CLUB_RELOU:
row["responsable"] = 3508
note = self.MAP_IDBDE[row["responsable"]] note = self.MAP_IDBDE[row["responsable"]]
if note == 6244: if note == 6244:
# Licorne magique ne doit pas utiliser son compte club pour proposer des activités # Licorne magique ne doit pas utiliser son compte club pour proposer des activités
note = Note.objects.get(pk=self.MAP_IDBDE[6524]) note = Note.objects.get(pk=self.MAP_IDBDE[6524])
note = note.id note = note.user_id
organizer = Club.objects.filter(name=row["signature"]) organizer = Club.objects.filter(name=row["signature"])
if organizer.exists(): if organizer.exists():
# Try to find the club that organizes the activity. # Try to find the club that organizes the activity.
@ -63,7 +57,7 @@ class Command(ImportCommand):
"name": row["titre"], "name": row["titre"],
"description": row["description"], "description": row["description"],
"activity_type_id": activity_type_id, # By default Pot "activity_type_id": activity_type_id, # By default Pot
"creater_id": NoteUser.objects.get(pk=note).user.id, "creater_id": note,
"organizer_id": organizer.pk, "organizer_id": organizer.pk,
"attendees_club_id": kfet.pk, # Maybe fix manually "attendees_club_id": kfet.pk, # Maybe fix manually
"date_start": make_aware(row["debut"]), "date_start": make_aware(row["debut"]),

View File

@ -4,9 +4,7 @@ import subprocess
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import call_command from django.core.management import call_command
from ._import_utils import ImportCommand class Command(BaseCommand):
class Command(ImportCommand):
""" """
Command for importing the database of NK15. Command for importing the database of NK15.
Need to be run by a user with a registered role in postgres for the database nk15. Need to be run by a user with a registered role in postgres for the database nk15.
@ -14,22 +12,8 @@ class Command(ImportCommand):
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
subprocess.call("./apps/scripts/shell/tabularasa") subprocess.call("./apps/scripts/shell/tabularasa")
call_command('import_account', alias=True, chunk=5000, save = "map.json")
kwargs["alias"] = True call_command('import_activities', chunk=5000, map="map.json")
kwargs["chunk"] = 1000 call_command('import_transaction', chunk=5000, buttons=True, map="map.json")
kwargs["save"] = "map.json"
call_command('import_account', **kwargs)
del kwargs["alias"]
del kwargs["save"]
kwargs["chunk"] = 100
kwargs["map"] = "map.json"
call_command('import_activities', **kwargs)
kwargs["chunk"] = 10000
kwargs["map"] = "map.json"
kwargs["buttons"] = True
call_command('import_transaction', **kwargs)
call_command('make_su','-sS', 'Coq', 'erdnaxe', 'PAC', 'Pollion', 'ÿnérant') call_command('make_su','-sS', 'Coq', 'erdnaxe', 'PAC', 'Pollion', 'ÿnérant')
call_command('syncsql') call_command('syncsql')

View File

@ -20,7 +20,7 @@ from note.models import (TemplateCategory,
from note.models import Note, NoteClub from note.models import Note, NoteClub
from activity.models import Guest, GuestTransaction from activity.models import Guest, GuestTransaction
from member.models import Membership, MembershipTransaction, Role from member.models import Membership
from ._import_utils import ImportCommand, BulkCreateManager, timed from ._import_utils import ImportCommand, BulkCreateManager, timed
# from member/fixtures/initial # from member/fixtures/initial
@ -63,7 +63,7 @@ class Command(ImportCommand):
parser.add_argument('-t', '--transactions', action='store', default=0, help="start id for transaction import") parser.add_argument('-t', '--transactions', action='store', default=0, help="start id for transaction import")
@timed @timed
def import_buttons(self, cur, chunk_size, import_buttons): def import_buttons(self, cur, chunk_size):
self.categories = dict() self.categories = dict()
self.buttons = dict() self.buttons = dict()
bulk_mgr = BulkCreateManager(chunk_size=chunk_size) bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
@ -72,7 +72,7 @@ class Command(ImportCommand):
for idx, row in enumerate(cur): for idx, row in enumerate(cur):
self.update_line(idx, n, row["label"]) self.update_line(idx, n, row["label"])
if row["categorie"] not in self.categories: if row["categorie"] not in self.categories:
cat = TemplateCategory.objects.get_or_create(name=row["categorie"])[0] cat = TemplateCategory.objects.create(name=row["categorie"])
cat.save() cat.save()
self.categories[row["categorie"]] = cat.pk self.categories[row["categorie"]] = cat.pk
obj_dict = { obj_dict = {
@ -86,7 +86,6 @@ class Command(ImportCommand):
} }
if row["label"] in self.buttons: if row["label"] in self.buttons:
obj_dict["name"] = f"{obj_dict['name']}_{obj_dict['destination_id']}" obj_dict["name"] = f"{obj_dict['name']}_{obj_dict['destination_id']}"
if import_buttons:
bulk_mgr.add(TransactionTemplate(**obj_dict)) bulk_mgr.add(TransactionTemplate(**obj_dict))
self.buttons[obj_dict["name"]] = (row["id"], self.categories[row["categorie"]]) self.buttons[obj_dict["name"]] = (row["id"], self.categories[row["categorie"]])
bulk_mgr.done() bulk_mgr.done()
@ -149,8 +148,6 @@ class Command(ImportCommand):
m = re.search(r"Invitation (.*?)(?:\s\()(.*?)\s(.*?)\)", row["description"]) m = re.search(r"Invitation (.*?)(?:\s\()(.*?)\s(.*?)\)", row["description"])
if m: if m:
first_name, last_name = m.group(2), m.group(3) first_name, last_name = m.group(2), m.group(3)
if first_name == "Marion" and last_name == "Bizu Pose":
first_name, last_name = "Marion Bizu", "Pose"
guest_id = Guest.objects.filter(first_name__iexact=first_name, guest_id = Guest.objects.filter(first_name__iexact=first_name,
last_name__iexact=last_name).first().pk last_name__iexact=last_name).first().pk
child_dict["guest_id"] = guest_id child_dict["guest_id"] = guest_id
@ -182,9 +179,6 @@ class Command(ImportCommand):
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError): except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1)) date = make_aware(row["transac_date"] + datetime.timedelta(hours=1))
if len(row["description"]) > 255:
row["description"] = row["description"][:252] + "..."
# standart transaction object # standart transaction object
obj_dict = { obj_dict = {
"pk": pk_transaction, "pk": pk_transaction,
@ -288,6 +282,6 @@ class Command(ImportCommand):
if kwargs["map"]: if kwargs["map"]:
self.load_map(kwargs["map"]) self.load_map(kwargs["map"])
self.import_buttons(cur, kwargs["chunk"], kwargs["buttons"]) self.import_buttons(cur, kwargs["chunk"])
self.import_transaction(cur, kwargs["chunk"], kwargs["transactions"]) self.import_transaction(cur, kwargs["chunk"], 0)
self.set_roles() self.set_roles()