A lot of route common params clean up
This commit is contained in:
@@ -424,6 +424,175 @@ def get_person_rec_list(
|
||||
# ### END ### API Person Methods ### get_person_rec_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### create_person_kiss() ###
|
||||
# Updated 2022-01-05
|
||||
def create_person_kiss(
|
||||
account_id: int,
|
||||
person_dict_obj: Person_Base,
|
||||
contact_id: int|None = None,
|
||||
organization_id: int|None = None,
|
||||
user_id: int|None = None,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
log.info('Create dictionary or Pydantic object')
|
||||
log.debug(type(person_dict_obj))
|
||||
if isinstance(person_dict_obj, dict):
|
||||
person_dict = person_dict_obj
|
||||
try:
|
||||
person_obj = Person_Base(**person_dict)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
else:
|
||||
person_obj = person_dict_obj
|
||||
person_obj.account_id = account_id
|
||||
|
||||
person_dict = person_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'contact_id', 'contact_id_random', 'email', 'cc_email', 'membership_person_id', 'membership_person_id_random', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
|
||||
if user_id:
|
||||
# Link to an existing user
|
||||
log.info(f'Adding user_id to person_dict. User ID: {user_id}')
|
||||
person_dict['user_id'] = user_id
|
||||
|
||||
if person_dict_in_result := sql_insert(data=person_dict, table_name='person', rm_id_random=True, id_random_length=default_num_bytes): pass
|
||||
else:
|
||||
log.warning(f'Person not created.')
|
||||
log.debug(person_dict_in_result)
|
||||
return False
|
||||
|
||||
log.debug(person_dict_in_result)
|
||||
person_id = person_dict_in_result
|
||||
|
||||
if contact_id and person.contact:
|
||||
log.info('Updating Contact object')
|
||||
if contact_update_result := update_contact(): pass
|
||||
else: return False
|
||||
elif person.contact:
|
||||
log.info('Creating Contact object')
|
||||
if contact_create_result := create_contact(
|
||||
account_id = account_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
): pass
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
if user_id and person.user:
|
||||
log.info('Updating User object')
|
||||
if user_update_result := update_user(): pass
|
||||
else: return False
|
||||
elif person.user:
|
||||
log.info('Creating User object')
|
||||
if user_create_result := create_user(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
): pass
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
return person_id
|
||||
# ### END ### API Person Methods ### create_person_kiss() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### update_person_kiss() ###
|
||||
# Updated 2022-01-05
|
||||
def update_person_kiss(
|
||||
person_id: int,
|
||||
person_dict_obj: Person_Base,
|
||||
contact_id: int|None = None,
|
||||
organization_id: int|None = None,
|
||||
user_id: int|None = None,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
log.info('Create dictionary or Pydantic object')
|
||||
log.debug(type(person_dict_obj))
|
||||
if isinstance(person_dict_obj, dict):
|
||||
person_dict = person_dict_obj
|
||||
try:
|
||||
person_obj = Person_Base(**person_dict)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
else:
|
||||
person_obj = person_dict_obj
|
||||
person_obj.account_id = account_id
|
||||
|
||||
person_dict = person_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'contact', 'contact_id', 'contact_id_random', 'email', 'cc_email', 'membership_person_id', 'membership_person_id_random', 'organization', 'user', 'created_on', 'updated_on'})
|
||||
|
||||
if user_id:
|
||||
# Link to an existing user
|
||||
log.info(f'Adding user_id to person_dict. User ID: {user_id}')
|
||||
person_dict['user_id'] = user_id
|
||||
|
||||
if person_dict_up_result := sql_update(data=person_dict, table_name='person', rm_id_random=True, id_random_length=default_num_bytes): pass
|
||||
else:
|
||||
log.warning(f'Person not updated.')
|
||||
log.debug(person_dict_up_result)
|
||||
return False
|
||||
|
||||
log.debug(person_dict_up_result)
|
||||
|
||||
if contact_id and person.contact:
|
||||
log.info('Updating Contact object')
|
||||
if contact_update_result := update_contact(
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
): pass
|
||||
else: return False
|
||||
elif person.contact:
|
||||
log.info('Creating Contact object')
|
||||
if contact_create_result := create_contact(
|
||||
account_id = account_id,
|
||||
contact_dict_obj = person_obj.contact,
|
||||
for_type = 'person',
|
||||
for_id = person_id,
|
||||
): pass
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
if user_id and person.user:
|
||||
log.info('Updating User object')
|
||||
if user_update_result := update_user(): pass
|
||||
else: return False
|
||||
elif person.user:
|
||||
log.info('Creating User object')
|
||||
if user_create_result := create_user(
|
||||
account_id = account_id,
|
||||
user_dict_obj = person_obj.user,
|
||||
person_id = person_id,
|
||||
):
|
||||
# user_id = user_create_result
|
||||
# person_data = {}
|
||||
# person_data['person_id'] = person_id
|
||||
# person_data['user_id'] = user_id
|
||||
|
||||
# if person_dict_up_result := sql_update(data=person_dict, table_name='person', rm_id_random=True, id_random_length=default_num_bytes): pass
|
||||
# else:
|
||||
# log.warning(f'Person not updated.')
|
||||
# log.debug(person_dict_up_result)
|
||||
# return False
|
||||
|
||||
# log.debug(person_dict_up_result)
|
||||
pass
|
||||
|
||||
else: return False
|
||||
else: pass
|
||||
|
||||
return True
|
||||
# ### END ### API Person Methods ### update_person_kiss() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Person Methods ### create_update_person_obj_v4b() ###
|
||||
def create_update_person_obj_v4b(
|
||||
account_id: int|str,
|
||||
|
||||
Reference in New Issue
Block a user