Working on IDAA membership imports

This commit is contained in:
Scott Idem
2021-08-16 18:15:44 -04:00
parent 8fd8b89ff4
commit 2f037290d9

View File

@@ -31,7 +31,18 @@ async def importing_person_data(
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
account_id = 19 allow_insert_person = True
allow_insert_contact = False
allow_insert_address = False
allow_insert_user = True
allow_update_person = False
allow_update_contact = False
allow_update_address = False
allow_update_user = False
# allow_update_person_new_user = True
account_id = 99
full_file_path = 'admin/temp/import_person_data.xlsx' full_file_path = 'admin/temp/import_person_data.xlsx'
df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_id':str, 'phone_home':str, 'phone_mobile':str, 'city':str, 'state_province':str, 'address_postal_code':str, 'country':str}) df = pandas.read_excel(full_file_path, na_filter=False, dtype={'external_id':str, 'phone_home':str, 'phone_mobile':str, 'city':str, 'state_province':str, 'address_postal_code':str, 'country':str})
@@ -56,7 +67,10 @@ async def importing_person_data(
user_id = None user_id = None
person_data = {} person_data = {}
if record['external_id']:
person_data['external_id'] = record['external_id'] person_data['external_id'] = record['external_id']
else:
person_data['external_id'] = record['email']
# person_data['informal_name'] = record['informal_name'] # person_data['informal_name'] = record['informal_name']
person_data['given_name'] = record['given_name'] person_data['given_name'] = record['given_name']
if record['middle_name']: if record['middle_name']:
@@ -119,6 +133,7 @@ async def importing_person_data(
address_id = person_rec.get('address_id', None) address_id = person_rec.get('address_id', None)
user_id = person_rec.get('user_id', None) user_id = person_rec.get('user_id', None)
person_data['id'] = person_id person_data['id'] = person_id
if allow_update_person:
if person_obj_up_result := sql_update(data=person_data, table_name='person'): if person_obj_up_result := sql_update(data=person_data, table_name='person'):
log.debug(person_obj_up_result) log.debug(person_obj_up_result)
else: else:
@@ -134,6 +149,7 @@ async def importing_person_data(
# INSERT new record # INSERT new record
log.debug('Found no records or something went wrong') log.debug('Found no records or something went wrong')
person_data['account_id'] = account_id person_data['account_id'] = account_id
if allow_insert_person:
if person_obj_in_result := sql_insert(data=person_data, table_name='person'): if person_obj_in_result := sql_insert(data=person_data, table_name='person'):
log.debug(person_obj_in_result) log.debug(person_obj_in_result)
person_id = person_obj_in_result # Should be an int person_id = person_obj_in_result # Should be an int
@@ -178,6 +194,7 @@ async def importing_person_data(
# UPDATE existing contact record # UPDATE existing contact record
log.info('UPDATE existing contact record') log.info('UPDATE existing contact record')
contact_data['id'] = contact_id contact_data['id'] = contact_id
if allow_update_contact:
if contact_obj_up_result := sql_update(data=contact_data, table_name='contact'): if contact_obj_up_result := sql_update(data=contact_data, table_name='contact'):
log.debug(contact_obj_up_result) log.debug(contact_obj_up_result)
else: else:
@@ -234,6 +251,7 @@ async def importing_person_data(
# UPDATE existing address record # UPDATE existing address record
log.info('UPDATE existing address record') log.info('UPDATE existing address record')
address_data['id'] = address_id address_data['id'] = address_id
if allow_update_address:
if address_obj_up_result := sql_update(data=address_data, table_name='address'): if address_obj_up_result := sql_update(data=address_data, table_name='address'):
log.debug(address_obj_up_result) log.debug(address_obj_up_result)
else: else:
@@ -282,6 +300,7 @@ async def importing_person_data(
# UPDATE existing user record # UPDATE existing user record
log.info('UPDATE existing user record') log.info('UPDATE existing user record')
user_data['id'] = user_id user_data['id'] = user_id
if allow_update_user:
if user_obj_up_result := sql_update(data=user_data, table_name='user'): if user_obj_up_result := sql_update(data=user_data, table_name='user'):
log.debug(user_obj_up_result) log.debug(user_obj_up_result)
else: else:
@@ -298,6 +317,7 @@ async def importing_person_data(
other_data['temp_password'] = random_password_string other_data['temp_password'] = random_password_string
user_data['other_json'] = json.dumps(other_data, indent=4) user_data['other_json'] = json.dumps(other_data, indent=4)
if allow_insert_user:
if user_obj_in_result := sql_insert(data=user_data, table_name='user'): if user_obj_in_result := sql_insert(data=user_data, table_name='user'):
log.debug(user_obj_in_result) log.debug(user_obj_in_result)
user_id = user_obj_in_result # Should be an int user_id = user_obj_in_result # Should be an int
@@ -315,9 +335,10 @@ async def importing_person_data(
person_data_up = {} person_data_up = {}
person_data_up['id'] = person_id person_data_up['id'] = person_id
person_data_up['user_id'] = user_id person_data_up['user_id'] = user_id
random_password_string # random_password_string
# Don't need to update with the new contact or address IDs that were just created. # Don't need to update with the new contact or address IDs that were just created.
if allow_insert_user: # Because this only matters on user INSERT
if person_obj_up_result := sql_update(data=person_data_up, table_name='person'): if person_obj_up_result := sql_update(data=person_data_up, table_name='person'):
log.debug(person_obj_up_result) log.debug(person_obj_up_result)
else: else: