Working on integration with Svelte and cont_edu_cert_person importing
This commit is contained in:
@@ -47,6 +47,8 @@ class Cont_Edu_Cert_Person_Base(BaseModel):
|
||||
# prefix: Optional[str]
|
||||
# suffix: Optional[str]
|
||||
full_name: Optional[str]
|
||||
informal_full_name: Optional[str]
|
||||
last_first_name: Optional[str]
|
||||
display_name: Optional[str]
|
||||
|
||||
title: Optional[str]
|
||||
@@ -62,6 +64,9 @@ class Cont_Edu_Cert_Person_Base(BaseModel):
|
||||
created_on: Optional[datetime.datetime] = None
|
||||
updated_on: Optional[datetime.datetime] = None
|
||||
|
||||
# Including JSON data
|
||||
other_json: Optional[Json]
|
||||
|
||||
# Including other related objects
|
||||
cont_edu_cert: Optional[Union[Cont_Edu_Cert_Base, None]]
|
||||
person: Optional[Union[Person_Base, None]]
|
||||
|
||||
@@ -330,3 +330,134 @@ async def importing_person_data(
|
||||
# break
|
||||
|
||||
return mk_resp(data=person_data_li)
|
||||
|
||||
|
||||
|
||||
@router.post('/cont_edu_cert_person_data', response_model=Resp_Body_Base)
|
||||
async def importing_cont_edu_cert_person_data(
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
account_id = 19
|
||||
cont_edu_cert_id = 3
|
||||
full_file_path = 'admin/temp/import_cont_edu_cert_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})
|
||||
log.debug(df)
|
||||
|
||||
df_dict = df.to_dict(orient='records')
|
||||
# log.debug(df_dict)
|
||||
|
||||
# return mk_resp(data=False, status_code=500)
|
||||
|
||||
cont_edu_cert_person_data_li = []
|
||||
# for i in df.index:
|
||||
for record in df_dict:
|
||||
cont_edu_cert_person_new = None
|
||||
person_id = None
|
||||
user_id = None
|
||||
cont_edu_cert_person_id = None
|
||||
|
||||
cont_edu_cert_person_data = {}
|
||||
cont_edu_cert_person_data['cont_edu_cert_id'] = cont_edu_cert_id
|
||||
cont_edu_cert_person_data['enable'] = True
|
||||
|
||||
cont_edu_cert_person_data['email'] = record['email']
|
||||
|
||||
cont_edu_cert_person_data['given_name'] = record['given_name']
|
||||
if record.get('middle_name', None):
|
||||
cont_edu_cert_person_data['middle_name'] = record['middle_name']
|
||||
else:
|
||||
cont_edu_cert_person_data['middle_name'] = None
|
||||
if record['family_name']:
|
||||
cont_edu_cert_person_data['family_name'] = record['family_name']
|
||||
else:
|
||||
cont_edu_cert_person_data['family_name'] = None
|
||||
|
||||
if cont_edu_cert_person_data['given_name'] and cont_edu_cert_person_data['middle_name'] and cont_edu_cert_person_data['family_name']:
|
||||
cont_edu_cert_person_data['full_name'] = cont_edu_cert_person_data['given_name']+' '+cont_edu_cert_person_data['middle_name']+' '+cont_edu_cert_person_data['family_name']
|
||||
elif cont_edu_cert_person_data['given_name'] and cont_edu_cert_person_data['family_name']:
|
||||
cont_edu_cert_person_data['full_name'] = cont_edu_cert_person_data['given_name']+' '+cont_edu_cert_person_data['family_name']
|
||||
elif cont_edu_cert_person_data['given_name']:
|
||||
cont_edu_cert_person_data['full_name'] = cont_edu_cert_person_data['family_name']
|
||||
elif record.get('informal_full_name', None):
|
||||
cont_edu_cert_person_data['full_name'] = record['informal_full_name']
|
||||
elif record['informal_name']:
|
||||
cont_edu_cert_person_data['full_name'] = record['informal_name']
|
||||
else:
|
||||
cont_edu_cert_person_data['full_name'] = None
|
||||
if record.get('informal_full_name', None):
|
||||
cont_edu_cert_person_data['informal_full_name'] = record['informal_full_name']
|
||||
else:
|
||||
cont_edu_cert_person_data['informal_full_name'] = None
|
||||
cont_edu_cert_person_data['last_first_name'] = record.get('last_first_name', None)
|
||||
|
||||
cont_edu_cert_person_data['display_name'] = record.get('display_name', None)
|
||||
# cont_edu_cert_person_data['created_on'] = record['created_on']
|
||||
# cont_edu_cert_person_data['updated_on'] = record['updated_on']
|
||||
|
||||
other_data = {}
|
||||
other_data['other_guest_of'] = record['other_guest_of']
|
||||
other_data['other_guest_li'] = record['other_guest_li']
|
||||
|
||||
cont_edu_cert_person_data['other_json'] = json.dumps(other_data, indent=4)
|
||||
|
||||
# Look up by email address and INSERT or UPDATE new cont_edu_cert_person record
|
||||
# Process the cont_edu_cert_person data
|
||||
log.debug(cont_edu_cert_person_data)
|
||||
# log.debug('*** *** *** *** END TEST RUN *** *** *** ***')
|
||||
# continue
|
||||
if cont_edu_cert_person_rec_li_result := sql_select(table_name='v_cont_edu_cert_person', field_name='email', field_value=cont_edu_cert_person_data['email']):
|
||||
if not isinstance(cont_edu_cert_person_rec_li_result, list):
|
||||
# Pull out IDs and UPDATE existing cont_edu_cert_person record
|
||||
log.debug('Found one record')
|
||||
cont_edu_cert_person_rec = cont_edu_cert_person_rec_li_result
|
||||
# person_id = cont_edu_cert_person_rec.get('person_id', None)
|
||||
# user_id = cont_edu_cert_person_rec.get('user_id', None)
|
||||
cont_edu_cert_person_data['id'] = cont_edu_cert_person_id
|
||||
if cont_edu_cert_person_obj_up_result := sql_update(data=cont_edu_cert_person_data, table_name='cont_edu_cert_person'):
|
||||
log.debug(cont_edu_cert_person_obj_up_result)
|
||||
else:
|
||||
log.warning(cont_edu_cert_person_obj_up_result)
|
||||
continue # Something unexpected may have happened
|
||||
else:
|
||||
log.warning('Found more than one record')
|
||||
log.warning(cont_edu_cert_person_rec_li_result)
|
||||
# Do nothing
|
||||
continue # Something unexpected may have happened
|
||||
cont_edu_cert_person_rec_li = cont_edu_cert_person_rec_li_result
|
||||
else:
|
||||
# INSERT new record
|
||||
log.debug('Found no records or something went wrong')
|
||||
cont_edu_cert_person_data['account_id'] = account_id
|
||||
if cont_edu_cert_person_obj_in_result := sql_insert(data=cont_edu_cert_person_data, table_name='cont_edu_cert_person'):
|
||||
log.debug(cont_edu_cert_person_obj_in_result)
|
||||
cont_edu_cert_person_id = cont_edu_cert_person_obj_in_result # Should be an int
|
||||
cont_edu_cert_person_new = True # Need to UPDATE this record after the contact, address, and user data is processed
|
||||
else:
|
||||
log.warning(cont_edu_cert_person_obj_in_result)
|
||||
continue # Something unexpected may have happened
|
||||
|
||||
|
||||
# if cont_edu_cert_person_new:
|
||||
# log.debug('Updating person record one more time since this is a new person')
|
||||
# cont_edu_cert_person_data_up = {}
|
||||
# cont_edu_cert_person_data_up['id'] = person_id
|
||||
# cont_edu_cert_person_data_up['user_id'] = user_id
|
||||
# random_password_string
|
||||
# # Don't need to update with the new contact or address IDs that were just created.
|
||||
|
||||
# if cont_edu_cert_person_obj_up_result := sql_update(data=cont_edu_cert_person_data_up, table_name='cont_edu_cert_person'):
|
||||
# log.debug(cont_edu_cert_person_obj_up_result)
|
||||
# else:
|
||||
# log.warning(cont_edu_cert_person_obj_up_result)
|
||||
# # break
|
||||
# continue # Something unexpected may have happened
|
||||
|
||||
cont_edu_cert_person_data_li.append(cont_edu_cert_person_data)
|
||||
log.debug(f"Record processed: {cont_edu_cert_person_id} {cont_edu_cert_person_data['full_name']}")
|
||||
# log.debug('*** *** *** *** END TEST RUN *** *** *** ***')
|
||||
# break
|
||||
|
||||
return mk_resp(data=cont_edu_cert_person_data_li)
|
||||
|
||||
Reference in New Issue
Block a user