Skip to content
GitLab
Explore
Sign in
Commits on Source (1)
🐛
Fix NK15 import
· f5967359
ynerant
authored
Jul 23, 2020
f5967359
Hide whitespace changes
Inline
Side-by-side
management/commands/import_nk15.py
View file @
f5967359
...
...
@@ -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
'
)
management/commands/import_transaction.py
View file @
f5967359
...
...
@@ -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
()
...
...