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

add support for GuestTransaction and timing

This commit is contained in:
Pierre-antoine Comby 2020-05-25 01:18:59 +02:00
parent df9888a31a
commit afe2c750b1

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
import re
import psycopg2 as pg
import psycopg2.extras as pge
import pytz
@ -16,9 +16,10 @@ from note.models import (TemplateCategory,
SpecialTransaction
)
from note.models import Note
from activity.models import Guest, GuestTransaction
from member.models import Membership, MembershipTransaction
from ._import_utils import ImportCommand, BulkCreateManager
from ._import_utils import ImportCommand, BulkCreateManager, timed
BDE_PK = 1
KFET_PK = 2
@ -48,6 +49,7 @@ class Command(ImportCommand):
parser.add_argument('-b', '--buttons', action='store_true', help="import buttons")
parser.add_argument('-t', '--transactions', action='store', default=0, help="start id for transaction import")
@timed
@transaction.atomic
def import_buttons(self, cur, chunk_size):
categories = dict()
@ -78,6 +80,7 @@ class Command(ImportCommand):
bulk_mgr.done()
return buttons, categories
@timed
@transaction.atomic
def import_transaction(self, cur, chunk_size, idmin, buttons, categories):
bulk_mgr = BulkCreateManager(chunk_size=chunk_size)
@ -183,8 +186,16 @@ class Command(ImportCommand):
Membership(**kfet_dict),
)
elif ttype == "invitation":
print("invitation not supported yet:", ttype)
child_transaction = GuestTransaction
m = re.search(r"Invitation (.*?)(?:\s\()(.*?)\s(.*?)\)", row["description"])
if m:
first_name, last_name = m.groups(1), m.groups(2)
guest_id = Guest.object.filter(first_name__iexact=first_name,
last_name__iexact=last_name).first().pk
child_dict["guest_id"] = guest_id
else:
raise(f"Guest not Found {row['id']} {first_name}, last_name" )
bulk_mgr.add(Transaction(**obj_dict),
child_transaction(**child_dict))
pk_transaction += 1