Working on IDAA membership imports
This commit is contained in:
@@ -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 = {}
|
||||||
person_data['external_id'] = record['external_id']
|
if 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,11 +133,12 @@ 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 person_obj_up_result := sql_update(data=person_data, table_name='person'):
|
if allow_update_person:
|
||||||
log.debug(person_obj_up_result)
|
if person_obj_up_result := sql_update(data=person_data, table_name='person'):
|
||||||
else:
|
log.debug(person_obj_up_result)
|
||||||
log.warning(person_obj_up_result)
|
else:
|
||||||
continue # Something unexpected may have happened
|
log.warning(person_obj_up_result)
|
||||||
|
continue # Something unexpected may have happened
|
||||||
else:
|
else:
|
||||||
log.warning('Found more than one record')
|
log.warning('Found more than one record')
|
||||||
log.warning(person_rec_li_result)
|
log.warning(person_rec_li_result)
|
||||||
@@ -134,13 +149,14 @@ 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 person_obj_in_result := sql_insert(data=person_data, table_name='person'):
|
if allow_insert_person:
|
||||||
log.debug(person_obj_in_result)
|
if person_obj_in_result := sql_insert(data=person_data, table_name='person'):
|
||||||
person_id = person_obj_in_result # Should be an int
|
log.debug(person_obj_in_result)
|
||||||
person_new = True # Need to UPDATE this record after the contact, address, and user data is processed
|
person_id = person_obj_in_result # Should be an int
|
||||||
else:
|
person_new = True # Need to UPDATE this record after the contact, address, and user data is processed
|
||||||
log.warning(person_obj_in_result)
|
else:
|
||||||
continue # Something unexpected may have happened
|
log.warning(person_obj_in_result)
|
||||||
|
continue # Something unexpected may have happened
|
||||||
|
|
||||||
# Process the contact data
|
# Process the contact data
|
||||||
log.debug('Process the contact data')
|
log.debug('Process the contact data')
|
||||||
@@ -178,11 +194,12 @@ 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 contact_obj_up_result := sql_update(data=contact_data, table_name='contact'):
|
if allow_update_contact:
|
||||||
log.debug(contact_obj_up_result)
|
if contact_obj_up_result := sql_update(data=contact_data, table_name='contact'):
|
||||||
else:
|
log.debug(contact_obj_up_result)
|
||||||
log.warning(contact_obj_up_result)
|
else:
|
||||||
continue # Something unexpected may have happened
|
log.warning(contact_obj_up_result)
|
||||||
|
continue # Something unexpected may have happened
|
||||||
elif person_id:
|
elif person_id:
|
||||||
# INSERT new contact record and link to person record
|
# INSERT new contact record and link to person record
|
||||||
log.info('INSERT new contact record and link to person record')
|
log.info('INSERT new contact record and link to person record')
|
||||||
@@ -234,11 +251,12 @@ 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 address_obj_up_result := sql_update(data=address_data, table_name='address'):
|
if allow_update_address:
|
||||||
log.debug(address_obj_up_result)
|
if address_obj_up_result := sql_update(data=address_data, table_name='address'):
|
||||||
else:
|
log.debug(address_obj_up_result)
|
||||||
log.warning(address_obj_up_result)
|
else:
|
||||||
# continue # Something unexpected may have happened
|
log.warning(address_obj_up_result)
|
||||||
|
# continue # Something unexpected may have happened
|
||||||
elif contact_id:
|
elif contact_id:
|
||||||
# INSERT new address record and link to contact record
|
# INSERT new address record and link to contact record
|
||||||
log.info('INSERT new address record and link to contact record')
|
log.info('INSERT new address record and link to contact record')
|
||||||
@@ -282,11 +300,12 @@ 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 user_obj_up_result := sql_update(data=user_data, table_name='user'):
|
if allow_update_user:
|
||||||
log.debug(user_obj_up_result)
|
if user_obj_up_result := sql_update(data=user_data, table_name='user'):
|
||||||
else:
|
log.debug(user_obj_up_result)
|
||||||
log.warning(user_obj_up_result)
|
else:
|
||||||
continue # Something unexpected may have happened
|
log.warning(user_obj_up_result)
|
||||||
|
continue # Something unexpected may have happened
|
||||||
elif person_id:
|
elif person_id:
|
||||||
# INSERT new user record and link to person record
|
# INSERT new user record and link to person record
|
||||||
log.info('INSERT new user record and link to person record')
|
log.info('INSERT new user record and link to person record')
|
||||||
@@ -298,14 +317,15 @@ 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 user_obj_in_result := sql_insert(data=user_data, table_name='user'):
|
if allow_insert_user:
|
||||||
log.debug(user_obj_in_result)
|
if user_obj_in_result := sql_insert(data=user_data, table_name='user'):
|
||||||
user_id = user_obj_in_result # Should be an int
|
log.debug(user_obj_in_result)
|
||||||
person_new = True # Need to UPDATE this record after the contact, address, and user data is processed
|
user_id = user_obj_in_result # Should be an int
|
||||||
else:
|
person_new = True # Need to UPDATE this record after the contact, address, and user data is processed
|
||||||
log.debug(user_obj_in_result)
|
else:
|
||||||
# break
|
log.debug(user_obj_in_result)
|
||||||
continue # Something unexpected may have happened
|
# break
|
||||||
|
continue # Something unexpected may have happened
|
||||||
else:
|
else:
|
||||||
log.error('No user ID to update or person ID to create a user linked to the person.')
|
log.error('No user ID to update or person ID to create a user linked to the person.')
|
||||||
return False
|
return False
|
||||||
@@ -315,15 +335,16 @@ 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 person_obj_up_result := sql_update(data=person_data_up, table_name='person'):
|
if allow_insert_user: # Because this only matters on user INSERT
|
||||||
log.debug(person_obj_up_result)
|
if person_obj_up_result := sql_update(data=person_data_up, table_name='person'):
|
||||||
else:
|
log.debug(person_obj_up_result)
|
||||||
log.warning(person_obj_up_result)
|
else:
|
||||||
# break
|
log.warning(person_obj_up_result)
|
||||||
continue # Something unexpected may have happened
|
# break
|
||||||
|
continue # Something unexpected may have happened
|
||||||
|
|
||||||
person_data_li.append(person_data)
|
person_data_li.append(person_data)
|
||||||
log.debug(f"Record processed: {person_id} {person_data['full_name']}")
|
log.debug(f"Record processed: {person_id} {person_data['full_name']}")
|
||||||
|
|||||||
Reference in New Issue
Block a user