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

🐛 Fix NK15 import

This commit is contained in:
Yohann D'ANELLO 2020-07-23 07:21:29 +02:00
parent 6cfae5fd69
commit f5967359a9
2 changed files with 21 additions and 15 deletions

View File

@ -31,5 +31,5 @@ class Command(ImportCommand):
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', 'Krokmou', 'PAC', 'Pollion', 'TLinux', 'ÿnérant')
call_command('syncsql')

View File

@ -18,9 +18,9 @@ from note.models import (TemplateCategory,
MembershipTransaction,
)
from note.models import Note, NoteClub
from activity.models import Guest, GuestTransaction
from activity.models import Guest, GuestTransaction, Entry
from member.models import Membership, MembershipTransaction, Role
from member.models import Membership
from ._import_utils import ImportCommand, BulkCreateManager, timed
# from member/fixtures/initial
@ -143,17 +143,19 @@ class Command(ImportCommand):
return obj_dict, child_dict, SpecialTransaction
def _guest_transaction(self, row, obj_dict, child_dict):
# Currently GuestTransaction is related to a Guest.
# This is not ideal and should be change to the Entry of this Guest.
obj_dict["polymorphic_ctype"] = CT["GuestTransaction"]
m = re.search(r"Invitation (.*?)(?:\s\()(.*?)\s(.*?)\)", row["description"])
if m:
activity_name = m.group(1)
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,
last_name__iexact=last_name).first().pk
child_dict["guest_id"] = guest_id
entry_id = Entry.objects.filter(
activity__name__iexact=activity_name,
guest__first_name__iexact=first_name,
guest__last_name__iexact=last_name,
).first().pk
child_dict["entry_id"] = entry_id
else:
raise(f"Guest not Found {row['id']} {first_name}, last_name")
@ -182,9 +184,6 @@ class Command(ImportCommand):
except (pytz.NonExistentTimeError, pytz.AmbiguousTimeError):
date = make_aware(row["transac_date"] + datetime.timedelta(hours=1))
if len(row["description"]) > 255:
row["description"] = row["description"][:252] + "..."
# standart transaction object
obj_dict = {
"pk": pk_transaction,
@ -200,6 +199,8 @@ class Command(ImportCommand):
"source_alias": "",
"valid": row["valide"],
}
if len(obj_dict["reason"]) > 255:
obj_dict["reason"] = obj_dict["reason"][:252] + "..."
# for child transaction Models
child_dict = {"pk": pk_transaction}
ttype = row["type"]
@ -264,17 +265,22 @@ class Command(ImportCommand):
# create base transaction object and typed one
bulk_mgr.add(Transaction(**obj_dict))
if child_transaction is not None:
child_dict.update(obj_dict)
bulk_mgr.add(child_transaction(**child_dict))
pk_transaction += 1
bulk_mgr.done()
@timed
def set_roles(self):
bulk_mgr = BulkCreateManager(chunk_size=10000)
membership_ids = Membership.objects.values_list('id',flat=True)
for m_id in membership_ids:
bde_membership_ids = Membership.objects.filter(club__pk=BDE_PK).values_list('id', flat=True)
kfet_membership_ids = Membership.objects.filter(club__pk=KFET_PK).values_list('id', flat=True)
n = len(bde_membership_ids)
for idx, (m_bde_id, m_kfet_id) in enumerate(zip(bde_membership_ids, kfet_membership_ids)):
self.update_line(idx, n, str(idx))
bulk_mgr.add(
Membership.roles.through(membership_id=m_id,role_id=BDE_ROLE_PK),
Membership.roles.through(membership_id=m_id,role_id=KFET_ROLE_PK),
Membership.roles.through(membership_id=m_bde_id, role_id=BDE_ROLE_PK),
Membership.roles.through(membership_id=m_kfet_id, role_id=KFET_ROLE_PK),
)
bulk_mgr.done()