2020-01-09 05:21:18 +00:00
|
|
|
import django, sys, os
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings'
|
|
|
|
django.setup()
|
|
|
|
|
2020-01-19 06:58:51 +00:00
|
|
|
import datetime
|
|
|
|
from apiserver.api import models, old_models, utils
|
2020-01-09 05:21:18 +00:00
|
|
|
|
|
|
|
MEMBER_FIELDS = [
|
|
|
|
'id',
|
2020-01-13 08:01:42 +00:00
|
|
|
# email -> old_email
|
2020-01-11 00:47:13 +00:00
|
|
|
'first_name',
|
|
|
|
'last_name',
|
2020-01-09 05:21:18 +00:00
|
|
|
'preferred_name',
|
2020-01-11 00:47:13 +00:00
|
|
|
'status',
|
2020-01-09 05:21:18 +00:00
|
|
|
'phone',
|
2020-01-11 00:47:13 +00:00
|
|
|
'expire_date',
|
2020-01-09 05:21:18 +00:00
|
|
|
'current_start_date',
|
|
|
|
'application_date',
|
|
|
|
'vetted_date',
|
|
|
|
'monthly_fees',
|
|
|
|
'emergency_contact_name',
|
|
|
|
'emergency_contact_phone',
|
2020-01-13 03:18:41 +00:00
|
|
|
# minor -> is_minor
|
|
|
|
'birthdate',
|
|
|
|
'guardian_name',
|
|
|
|
'street_address',
|
|
|
|
# city, provice -> city
|
|
|
|
'postal_code',
|
2020-01-09 05:21:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
TRANSACTION_FIELDS = [
|
|
|
|
'id',
|
|
|
|
'member_id',
|
|
|
|
'date',
|
|
|
|
'amount',
|
|
|
|
'reference_number',
|
|
|
|
'memo',
|
|
|
|
'number_of_membership_months',
|
|
|
|
'payment_method',
|
|
|
|
'category',
|
|
|
|
'account_type',
|
|
|
|
'info_source',
|
|
|
|
]
|
|
|
|
|
2020-01-09 06:45:32 +00:00
|
|
|
CARD_FIELDS = [
|
|
|
|
'id',
|
|
|
|
'member_id',
|
|
|
|
'card_number',
|
|
|
|
'notes',
|
|
|
|
'last_seen_at',
|
|
|
|
'active_status',
|
|
|
|
]
|
|
|
|
|
2020-01-09 23:58:44 +00:00
|
|
|
COURSE_FIELDS = [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
# True -> is_old
|
|
|
|
]
|
|
|
|
|
|
|
|
SESSION_FIELDS = [
|
|
|
|
'id',
|
|
|
|
# course_id -> course
|
|
|
|
# instructor -> old_instructor
|
2020-01-16 09:46:11 +00:00
|
|
|
# datetime -> fix timezone
|
2020-01-09 23:58:44 +00:00
|
|
|
'cost',
|
|
|
|
]
|
|
|
|
|
|
|
|
TRAINING_FIELDS = [
|
|
|
|
'id',
|
|
|
|
# class_session_id -> session
|
|
|
|
'member_id',
|
2020-02-07 01:11:09 +00:00
|
|
|
# attendance_status -> capitalize
|
2020-01-09 23:58:44 +00:00
|
|
|
'sign_up_date',
|
|
|
|
'paid_date',
|
|
|
|
]
|
|
|
|
|
2020-01-11 06:27:30 +00:00
|
|
|
photo_folders = os.listdir('old_photos')
|
|
|
|
print('Found {} member photo folders'.format(len(photo_folders)))
|
|
|
|
|
|
|
|
|
2020-01-09 05:21:18 +00:00
|
|
|
print('Deleting all members...')
|
|
|
|
models.Member.objects.all().delete()
|
|
|
|
print('Importing old members...')
|
2020-01-09 23:58:44 +00:00
|
|
|
old = old_models.Members.objects.using('old_portal').all()
|
2020-01-09 05:21:18 +00:00
|
|
|
|
2020-02-07 04:10:13 +00:00
|
|
|
import_date = old.last().web_crawl_date.date()
|
|
|
|
print('Using import date:', import_date)
|
|
|
|
|
2020-01-09 23:58:44 +00:00
|
|
|
for o in old:
|
|
|
|
new = {}
|
2020-01-09 05:21:18 +00:00
|
|
|
|
|
|
|
for f in MEMBER_FIELDS:
|
2020-01-09 23:58:44 +00:00
|
|
|
new[f] = o.__dict__.get(f, None)
|
2020-01-09 05:21:18 +00:00
|
|
|
|
2020-01-13 03:18:41 +00:00
|
|
|
if o.city and o.province:
|
|
|
|
new['city'] = '{}, {}'.format(o.city, o.province)
|
2020-01-13 08:01:42 +00:00
|
|
|
new['old_email'] = o.email
|
2020-01-13 03:18:41 +00:00
|
|
|
new['is_minor'] = o.minor
|
2020-01-19 10:57:56 +00:00
|
|
|
new['paused_date'] = None
|
2020-01-13 03:18:41 +00:00
|
|
|
|
2020-01-11 06:27:30 +00:00
|
|
|
small, medium, large = None, None, None
|
|
|
|
if str(o.id) in photo_folders:
|
|
|
|
folder = 'old_photos/' + str(o.id)
|
|
|
|
if 'photo.jpg' in os.listdir(folder):
|
2020-01-23 22:32:31 +00:00
|
|
|
small, medium, large = utils.process_image_upload(folder + '/photo.jpg')
|
2020-01-11 06:27:30 +00:00
|
|
|
print('Found a photo')
|
|
|
|
|
|
|
|
models.Member.objects.create(photo_small=small, photo_medium=medium, photo_large=large, **new)
|
2020-01-09 23:58:44 +00:00
|
|
|
print('Imported member #{} - {} {}'.format(
|
|
|
|
o.id, o.first_name, o.last_name
|
2020-01-09 05:21:18 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
print('Deleting all transactions...')
|
|
|
|
models.Transaction.objects.all().delete()
|
2020-01-19 10:57:56 +00:00
|
|
|
print('Importing old transactions...')
|
|
|
|
old = old_models.Transactions.objects.using('old_portal').all()
|
|
|
|
|
|
|
|
for o in old:
|
|
|
|
new = {}
|
|
|
|
|
|
|
|
for f in TRANSACTION_FIELDS:
|
2020-02-06 09:52:10 +00:00
|
|
|
tmp = o.__dict__.get(f, None)
|
|
|
|
if isinstance(tmp, str):
|
|
|
|
new[f] = tmp.replace('Paypal', 'PayPal')
|
|
|
|
else:
|
|
|
|
new[f] = tmp
|
2020-01-19 10:57:56 +00:00
|
|
|
|
|
|
|
models.Transaction.objects.create(**new)
|
|
|
|
print('Imported transaction #{} - {} {}'.format(
|
|
|
|
o.id, o.member_id, o.category
|
|
|
|
))
|
|
|
|
|
2020-01-19 06:58:51 +00:00
|
|
|
print('Faking membership months...')
|
|
|
|
members = models.Member.objects.all()
|
|
|
|
bad_count = 0
|
|
|
|
|
|
|
|
for m in members:
|
|
|
|
old_status = m.status
|
|
|
|
old_expire = m.expire_date
|
|
|
|
|
|
|
|
if 'Former' in old_status:
|
|
|
|
m.status = 'Old Portal ' + old_status
|
|
|
|
m.save()
|
|
|
|
continue
|
2020-01-19 10:57:56 +00:00
|
|
|
if not m.current_start_date: continue
|
2020-01-19 06:58:51 +00:00
|
|
|
|
2020-01-20 00:46:07 +00:00
|
|
|
tx, _ = utils.fake_missing_membership_months(m)
|
2020-01-19 06:58:51 +00:00
|
|
|
utils.tally_membership_months(m, import_date)
|
2020-01-26 22:17:05 +00:00
|
|
|
utils.gen_member_forms(m)
|
2020-01-19 06:58:51 +00:00
|
|
|
|
2020-01-20 00:29:28 +00:00
|
|
|
if tx:
|
|
|
|
print(m.first_name, m.last_name, tx.memo)
|
2020-01-19 06:58:51 +00:00
|
|
|
|
|
|
|
if old_status != m.status or old_expire != m.expire_date:
|
2020-01-19 10:57:56 +00:00
|
|
|
print('Expire / status mismatch member:', m.__dict__)
|
2020-01-19 06:58:51 +00:00
|
|
|
print('New status:', m.status)
|
|
|
|
print('Old status:', old_status)
|
2020-01-20 00:29:28 +00:00
|
|
|
print('New expire:', m.expire_date)
|
2020-01-19 06:58:51 +00:00
|
|
|
print('Old expire:', old_expire)
|
2020-01-20 00:29:28 +00:00
|
|
|
print('')
|
2020-01-19 06:58:51 +00:00
|
|
|
bad_count += 1
|
|
|
|
|
|
|
|
print('Import mismatch count:', bad_count)
|
|
|
|
|
|
|
|
print('Pausing former members...')
|
|
|
|
for m in members:
|
|
|
|
if 'Former' in m.status:
|
|
|
|
paused_date = m.expire_date or datetime.date.today()
|
2020-01-19 10:57:56 +00:00
|
|
|
m.paused_date = paused_date
|
|
|
|
m.save()
|
|
|
|
print('Paused', m.first_name, m.last_name)
|
2020-01-09 05:21:18 +00:00
|
|
|
|
|
|
|
|
2020-01-19 06:58:51 +00:00
|
|
|
|
2020-01-09 06:45:32 +00:00
|
|
|
print('Deleting all cards...')
|
|
|
|
models.Card.objects.all().delete()
|
|
|
|
print('Importing old cards...')
|
2020-01-09 23:58:44 +00:00
|
|
|
old = old_models.AccessKeys.objects.using('old_portal').all()
|
2020-01-09 06:45:32 +00:00
|
|
|
|
2020-01-09 23:58:44 +00:00
|
|
|
for o in old:
|
|
|
|
new = {}
|
2020-01-09 06:45:32 +00:00
|
|
|
|
|
|
|
for f in CARD_FIELDS:
|
2020-01-09 23:58:44 +00:00
|
|
|
new[f] = o.__dict__.get(f, None)
|
|
|
|
|
|
|
|
models.Card.objects.create(**new)
|
|
|
|
print('Imported card #{} - {} {}'.format(
|
|
|
|
o.id, o.card_number, o.notes
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
print('Deleting all courses...')
|
|
|
|
models.Course.objects.all().delete()
|
|
|
|
print('Importing old courses...')
|
|
|
|
old = old_models.Courses.objects.using('old_portal').all()
|
|
|
|
|
|
|
|
for o in old:
|
|
|
|
new = {}
|
|
|
|
|
|
|
|
for f in COURSE_FIELDS:
|
|
|
|
new[f] = o.__dict__.get(f, None)
|
|
|
|
new['name'] = new['name'].split('<',1)[0]
|
|
|
|
new['is_old'] = True
|
|
|
|
|
|
|
|
models.Course.objects.create(**new)
|
|
|
|
print('Imported course #{} - {}'.format(
|
|
|
|
o.id, new['name']
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
print('Deleting all sessions...')
|
|
|
|
models.Session.objects.all().delete()
|
|
|
|
print('Importing old session...')
|
|
|
|
old = old_models.ClassSessions.objects.using('old_portal').all()
|
|
|
|
|
|
|
|
for o in old:
|
|
|
|
new = {}
|
|
|
|
|
|
|
|
for f in SESSION_FIELDS:
|
|
|
|
new[f] = o.__dict__.get(f, None)
|
|
|
|
new['course'] = models.Course.objects.get(id=o.course_id)
|
|
|
|
new['old_instructor'] = o.instructor
|
2020-01-17 04:16:09 +00:00
|
|
|
new['datetime'] = str(o.datetime).replace('+00:00', '-07:00')
|
2020-01-09 23:58:44 +00:00
|
|
|
|
|
|
|
models.Session.objects.create(**new)
|
|
|
|
print('Imported session #{} - {} {}'.format(
|
|
|
|
o.id, o.instructor, new['course']
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
print('Deleting all training...')
|
|
|
|
models.Training.objects.all().delete()
|
|
|
|
print('Importing old training...')
|
|
|
|
old = old_models.ClassRegistrants.objects.using('old_portal').all()
|
|
|
|
|
|
|
|
for o in old:
|
|
|
|
new = {}
|
|
|
|
|
|
|
|
for f in TRAINING_FIELDS:
|
|
|
|
new[f] = o.__dict__.get(f, None)
|
|
|
|
new['session'] = models.Session.objects.get(id=o.class_session_id)
|
2020-02-07 01:11:09 +00:00
|
|
|
new['attendance_status'] = o.attendance_status.capitalize()
|
2020-01-09 06:45:32 +00:00
|
|
|
|
2020-01-09 23:58:44 +00:00
|
|
|
models.Training.objects.create(**new)
|
|
|
|
print('Imported training #{} - {} {}'.format(
|
|
|
|
o.id, new['session'], o.member_id
|
2020-01-09 06:45:32 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
|
2020-01-09 05:21:18 +00:00
|
|
|
print('Done.')
|