Work on importing person and membership data
This commit is contained in:
@@ -31,12 +31,14 @@ router = APIRouter()
|
||||
async def importing_update_w_external_id(
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
account_id = 13
|
||||
full_file_path = 'admin/temp/import_person_external_id.csv'
|
||||
|
||||
log.info(f'Starting import for Account ID {account_id} File Name: {full_file_path}')
|
||||
|
||||
df = pandas.read_csv(full_file_path, na_filter=False, dtype={'external_id':str, 'External ID':str, 'source_id':str, 'Source ID':str, 'email':str, 'Email Address':str})
|
||||
log.debug(df)
|
||||
|
||||
@@ -84,7 +86,7 @@ async def importing_update_w_external_id(
|
||||
person_id = person_rec.get('person_id', None)
|
||||
person_id_random = person_rec.get('person_id_random', None)
|
||||
full_name = person_rec.get('full_name', None)
|
||||
log.info(f'Found one record. Person ID: {person_id_random} Person Full Name: {full_name}')
|
||||
log.warning(f'Found one record. Person ID: {person_id_random} Person Full Name: {full_name}')
|
||||
# contact_id = person_rec.get('contact_id', None)
|
||||
# address_id = person_rec.get('address_id', None)
|
||||
# user_id = person_rec.get('user_id', None)
|
||||
@@ -263,7 +265,7 @@ async def ins_up_person_contact_address_user_data(
|
||||
|
||||
if external_id := record.get('external_id', None): pass
|
||||
else:
|
||||
log.info('No external ID was found.')
|
||||
log.warning('No external ID was found.')
|
||||
continue
|
||||
|
||||
if source_id := record.get('source_id', None): pass
|
||||
@@ -273,7 +275,7 @@ async def ins_up_person_contact_address_user_data(
|
||||
|
||||
if email := record.get('email', None): pass
|
||||
else:
|
||||
log.info('No email address was found.')
|
||||
log.warning('No email address was found.')
|
||||
continue
|
||||
log.debug(f'External ID: {external_id}, Source ID {source_id}, Email: {email}')
|
||||
|
||||
@@ -342,6 +344,8 @@ async def ins_up_person_contact_address_user_data(
|
||||
if paper_mail_opt_out == 'Yes': person_data['paper_mail_allowed'] = False
|
||||
if paper_mail_opt_out == 'No' or paper_mail_opt_out == 0: person_data['paper_mail_allowed'] = True
|
||||
|
||||
person_data['enable'] = True
|
||||
|
||||
if created_on := record.get('created_on'):
|
||||
person_data['created_on'] = datetime.datetime.strptime(created_on, '%d-%b-%Y')
|
||||
if updated_on := record.get('updated_on'):
|
||||
@@ -373,12 +377,21 @@ async def ins_up_person_contact_address_user_data(
|
||||
# continue
|
||||
data = {}
|
||||
data['account_id'] = account_id
|
||||
data['external_id'] = external_id
|
||||
data['external_import_id'] = external_import_id
|
||||
# sql = f"""
|
||||
# SELECT *
|
||||
# FROM `v_person` AS `person`
|
||||
# WHERE person.account_id = :account_id
|
||||
# AND person.external_import_id = :external_import_id
|
||||
# LIMIT 1;
|
||||
# """
|
||||
|
||||
sql = f"""
|
||||
SELECT *
|
||||
FROM `v_person` AS `person`
|
||||
WHERE person.account_id = :account_id
|
||||
AND person.external_import_id = :external_import_id
|
||||
AND person.external_id = :external_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
@@ -413,7 +426,7 @@ async def ins_up_person_contact_address_user_data(
|
||||
continue
|
||||
else:
|
||||
# INSERT new record
|
||||
log.debug('Found no records or something went wrong')
|
||||
log.debug('Found no records or something went wrong. Creating a new record...')
|
||||
person_data['account_id'] = account_id
|
||||
if allow_insert_person:
|
||||
if person_obj_in_result := sql_insert(data=person_data, table_name='person'):
|
||||
@@ -475,6 +488,8 @@ async def ins_up_person_contact_address_user_data(
|
||||
if record.get('linkedin_url'): contact_data['linkedin_url'] = record.get('linkedin_url')
|
||||
if record.get('twitter_url'): contact_data['twitter_url'] = record.get('twitter_url')
|
||||
|
||||
contact_data['enable'] = True
|
||||
|
||||
log.debug(contact_data)
|
||||
if contact_id:
|
||||
# UPDATE existing contact record
|
||||
@@ -535,6 +550,8 @@ async def ins_up_person_contact_address_user_data(
|
||||
address_data['country_alpha_2_code'] = None
|
||||
if record.get('home_address_country_name', None): address_data['country'] = record.get('home_address_country_name', None)
|
||||
|
||||
address_data['enable'] = True
|
||||
|
||||
log.debug(address_data)
|
||||
if address_id:
|
||||
# UPDATE existing address record
|
||||
@@ -572,13 +589,13 @@ async def ins_up_person_contact_address_user_data(
|
||||
user_data['email'] = record['email']
|
||||
user_data['email_verified'] = contact_data.get('email_active', False) # Not perfect, but a good start
|
||||
|
||||
user_data['enable'] = False
|
||||
user_data['enable'] = True
|
||||
user_data['enable_from'] = datetime.datetime.now(datetime.timezone.utc)
|
||||
user_data['enable_to'] = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=365)
|
||||
|
||||
user_data['super'] = False
|
||||
user_data['manager'] = False
|
||||
user_data['administrator'] = False
|
||||
# user_data['administrator'] = False
|
||||
|
||||
user_data['public'] = False
|
||||
user_data['verified'] = True
|
||||
@@ -590,7 +607,7 @@ async def ins_up_person_contact_address_user_data(
|
||||
user_data['id'] = user_id
|
||||
user_data.pop('enable')
|
||||
user_data.pop('email_verified')
|
||||
user_data.pop('administrator')
|
||||
# user_data.pop('administrator')
|
||||
user_data.pop('notes')
|
||||
log.debug(user_data)
|
||||
if allow_update_user:
|
||||
|
||||
Reference in New Issue
Block a user