Working on event person, registration, badge, session, presentation, and presenter create and update. _v3 things
This commit is contained in:
@@ -339,11 +339,13 @@ def get_person_rec_w_external_id(
|
||||
# ### END ### API Person Methods ### get_person_rec_w_external_id() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### create_person_obj() ###
|
||||
# ### BEGIN ### API Person Methods ### create_person_obj_v3() ###
|
||||
# NOTE: This will create a person and then also create a linked contact if person_obj.contact data is passed. The create_contact_obj will create a contact and then also create a linked address if person_obj.contact.address data is passed.
|
||||
# Reviewed and updated 2021-08-24
|
||||
# Reviewed and updated 2021-08-21
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_person_obj(
|
||||
def create_person_obj_v3(
|
||||
account_id: int|str,
|
||||
person_obj_new: Person_Base,
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
@@ -352,6 +354,9 @@ def create_person_obj(
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
||||
else: return False
|
||||
|
||||
person_obj_data = person_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
log.debug(person_obj_data)
|
||||
|
||||
@@ -370,30 +375,199 @@ def create_person_obj(
|
||||
return_dict['contact']['address_id'] = None
|
||||
return_dict['user_id'] = None
|
||||
|
||||
if person_obj_new.contact:
|
||||
log.info(f'Contact data was found. Create a new contact and link it to the new person. Person ID: {person_id}')
|
||||
contact_obj_new = person_obj_new.contact
|
||||
contact_obj_new.for_type = 'person'
|
||||
contact_obj_new.for_id = person_id
|
||||
create_contact_obj_result = create_contact_obj(contact_obj_new=contact_obj_new)
|
||||
if isinstance(create_contact_obj_result, int):
|
||||
contact_id = create_contact_obj_result
|
||||
log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
if person_obj_new.contact and isinstance(person_obj_new.contact, dict):
|
||||
log.info(f'Contact was found. Create a new Contact and link it to the new Person or update existing Contact. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
contact_obj_unknown = person_obj_new.contact
|
||||
log.debug(contact_obj_unknown)
|
||||
if contact_id := contact_obj_unknown.get('contact_id_random', None):
|
||||
log.warning('Contact ID found. This is not expected, but should be ok.')
|
||||
from app.methods.contact_methods import update_contact_obj_v3
|
||||
if update_contact_obj_result := update_contact_obj(
|
||||
contact_id = contact_id,
|
||||
contact_obj_up = contact_obj_unknown,
|
||||
create_missing_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
contact_id = update_contact_obj_result
|
||||
log.info(f'Contact updated. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not updated. Person ID: {person_id}')
|
||||
log.debug(update_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_contact_obj_result, int):
|
||||
contact_id = update_contact_obj_result
|
||||
log.info(f'Contact updated. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not updated. Person ID: {person_id}')
|
||||
log.debug(update_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No Contact ID found.')
|
||||
# from app.methods.contact_methods import create_contact_obj
|
||||
|
||||
contact_obj_unknown = person_obj_new.contact
|
||||
contact_obj_unknown.for_type = 'person'
|
||||
contact_obj_unknown.for_id = person_id
|
||||
|
||||
if create_contact_obj_result := create_contact_obj(
|
||||
contact_obj_new = contact_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_contact_obj_result, int):
|
||||
contact_id = create_contact_obj_result
|
||||
log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
log.debug(create_contact_obj_result)
|
||||
contact_id = None
|
||||
if fail_any: return False
|
||||
return_dict['contact_id'] = contact_id
|
||||
else:
|
||||
log.info('Contact not found or not in a dict.')
|
||||
pass
|
||||
|
||||
# NOTE: This is the older pre v3 version
|
||||
# if person_obj_new.contact:
|
||||
# log.info(f'Contact was found. Create a new Contact and link it to the new Person or update existing Contact. Person ID: {person_id}')
|
||||
# contact_obj_new = person_obj_new.contact
|
||||
# contact_obj_new.for_type = 'person'
|
||||
# contact_obj_new.for_id = person_id
|
||||
# create_contact_obj_result = create_contact_obj(contact_obj_new=contact_obj_new)
|
||||
# if isinstance(create_contact_obj_result, int):
|
||||
# contact_id = create_contact_obj_result
|
||||
# log.info(f'Contact created. Contact ID: {contact_id}')
|
||||
# else:
|
||||
# log.warning(f'Contact not created. Person ID: {person_id}')
|
||||
# log.debug(create_contact_obj_result)
|
||||
# contact_id = None
|
||||
# if fail_any: return False
|
||||
|
||||
if person_obj_new.organization and isinstance(person_obj_new.organization, dict):
|
||||
log.info(f'Organization was found. Create a new Organization and link it to the new Person or update existing Organization. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
organization_obj_unknown = person_obj_new.organization
|
||||
log.debug(organization_obj_unknown)
|
||||
if organization_id := organization_obj_unknown.get('organization_id_random', None):
|
||||
log.warning('Organization ID found. This is not expected, but should be ok.')
|
||||
# from app.methods.organization_methods import update_organization_obj_v3
|
||||
if update_organization_obj_result := update_organization_obj(
|
||||
organization_id = organization_id,
|
||||
organization_obj_up = organization_obj_unknown,
|
||||
create_missing_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
organization_id = update_organization_obj_result
|
||||
log.info(f'Organization updated. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not updated. Person ID: {person_id}')
|
||||
log.debug(update_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_organization_obj_result, int):
|
||||
organization_id = update_organization_obj_result
|
||||
log.info(f'Organization updated. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not updated. Person ID: {person_id}')
|
||||
log.debug(update_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No Organization ID found.')
|
||||
# from app.methods.organization_methods import create_organization_obj_v3
|
||||
if create_organization_obj_result := create_organization_obj(
|
||||
organization_obj_new = organization_obj_unknown,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_organization_obj_result, int):
|
||||
organization_id = create_organization_obj_result
|
||||
log.info(f'Organization created. Organization ID: {organization_id}')
|
||||
else:
|
||||
log.warning(f'Organization not created. Person ID: {person_id}')
|
||||
log.debug(create_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'Organization not created. Person ID: {person_id}')
|
||||
log.debug(create_organization_obj_result)
|
||||
organization_id = None
|
||||
if fail_any: return False
|
||||
return_dict['organization_id'] = organization_id
|
||||
else:
|
||||
log.info('Organization not found or not in a dict.')
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
if person_obj_new.user and isinstance(person_obj_new.user, dict):
|
||||
log.info(f'User was found. Create a new User and link it to the new Person or update existing User. Person ID: {person_id}')
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
user_obj_unknown = person_obj_new.user
|
||||
log.debug(user_obj_unknown)
|
||||
if user_id := user_obj_unknown.get('user_id_random', None):
|
||||
log.warning('User ID found. This is not expected, but should be ok.')
|
||||
from app.methods.user_methods import update_user_obj_v3
|
||||
if update_user_obj_result := update_user_obj_v3(
|
||||
user_id = user_id,
|
||||
user_obj_up = user_obj_unknown,
|
||||
# create_missing_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
user_id = update_user_obj_result
|
||||
log.info(f'User updated. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not updated. Person ID: {person_id}')
|
||||
log.debug(update_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if isinstance(update_user_obj_result, int):
|
||||
user_id = update_user_obj_result
|
||||
log.info(f'User updated. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not updated. Person ID: {person_id}')
|
||||
log.debug(update_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.info(f'No User ID found.')
|
||||
from app.methods.user_methods import create_user_obj_v3
|
||||
|
||||
user_obj_unknown = person_obj_new.user
|
||||
user_obj_unknown.for_type = 'person'
|
||||
user_obj_unknown.for_id = person_id
|
||||
|
||||
if create_user_obj_result := create_user_obj_v3(
|
||||
user_obj_new = user_obj_unknown,
|
||||
# create_sub_obj = create_sub_obj,
|
||||
# fail_any = fail_any,
|
||||
):
|
||||
if isinstance(create_user_obj_result, int):
|
||||
user_id = create_user_obj_result
|
||||
log.info(f'User created. User ID: {user_id}')
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
if person_obj_new.user:
|
||||
log.info(f'User data was found. Create a new user and link it to the new person. Person ID: {person_id}')
|
||||
from app.methods.user_methods import create_user_obj
|
||||
user_obj_new = person_obj_new.user
|
||||
user_obj_new.person_id = person_id
|
||||
create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
if isinstance(create_user_obj_result, int):
|
||||
log.info(f'User created. User ID: {user_id} Update person {person_id} with new user ID.')
|
||||
user_id = create_user_obj_result
|
||||
# Need to update the person with the new user_id
|
||||
person_obj_up = {}
|
||||
person_obj_up['id'] = person_id
|
||||
@@ -404,15 +578,42 @@ def create_person_obj(
|
||||
log.warning(f'Person not updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
if fail_any: return False
|
||||
log.debug(person_obj_up_result)
|
||||
else:
|
||||
log.warning(f'User not created. Person ID: {person_id}')
|
||||
log.debug(create_user_obj_result)
|
||||
user_id = None
|
||||
if fail_any: return False
|
||||
|
||||
return_dict['user_id'] = user_id
|
||||
else:
|
||||
log.info('User not found or not in a dict.')
|
||||
pass
|
||||
|
||||
|
||||
# NOTE: This is the older pre v3 version
|
||||
# if person_obj_new.user:
|
||||
# log.info(f'User data was found. Create a new user and link it to the new person. Person ID: {person_id}')
|
||||
# from app.methods.user_methods import create_user_obj
|
||||
# user_obj_new = person_obj_new.user
|
||||
# user_obj_new.person_id = person_id
|
||||
# create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
# if isinstance(create_user_obj_result, int):
|
||||
# log.info(f'User created. User ID: {user_id} Update person {person_id} with new user ID.')
|
||||
# user_id = create_user_obj_result
|
||||
# # Need to update the person with the new user_id
|
||||
# person_obj_up = {}
|
||||
# person_obj_up['id'] = person_id
|
||||
# person_obj_up['user_id'] = user_id
|
||||
# if person_obj_up_result := sql_update(data=person_obj_up, table_name='person'):
|
||||
# log.info(f'Person updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
# else:
|
||||
# log.warning(f'Person not updated with user ID. Person ID: {person_id} User ID: {user_id}')
|
||||
# if fail_any: return False
|
||||
# log.debug(person_obj_up_result)
|
||||
# else:
|
||||
# log.warning(f'User not created. Person ID: {person_id}')
|
||||
# log.debug(create_user_obj_result)
|
||||
# user_id = None
|
||||
# if fail_any: return False
|
||||
|
||||
log.debug(f'Returning the new person_id: {person_id}')
|
||||
return person_id
|
||||
# ### END ### API Person Methods ### create_person_obj() ###
|
||||
# ### END ### API Person Methods ### create_person_obj_v3() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### update_person_obj() ###
|
||||
|
||||
Reference in New Issue
Block a user