A lot of code clean up! Also adding in Response everywhere...

This commit is contained in:
Scott Idem
2021-08-10 18:09:34 -04:00
parent 73466456ee
commit d933395a9f
57 changed files with 290 additions and 147 deletions

View File

@@ -293,6 +293,8 @@ def get_person_rec_list(
# ### BEGIN ### API Person Methods ### create_person_obj() ###
# 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-10
def create_person_obj(person_obj_new:Person_Base):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -319,14 +321,15 @@ def create_person_obj(person_obj_new:Person_Base):
if isinstance(create_contact_obj_result, int):
contact_id = create_contact_obj_result
log.debug(f'Update person with new contact_id: {contact_id}')
# NOTE: This last update should no longer be needed now that the person.contact_id is not supposed to be used.
# Need to update the person with the new contact_id
person_obj_up = {}
person_obj_up['id'] = person_id
person_obj_up['contact_id_old'] = contact_id
if person_obj_up_result := sql_update(data=person_obj_up, table_name='person'): pass
else:
return False
log.debug(person_obj_up_result)
person_obj_up = {} # REMOVE
person_obj_up['id'] = person_id # REMOVE
person_obj_up['contact_id_old'] = contact_id # REMOVE
if person_obj_up_result := sql_update(data=person_obj_up, table_name='person'): pass # REMOVE
else: # REMOVE
return False # REMOVE
log.debug(person_obj_up_result) # REMOVE
else:
log.debug(f'No contact_id was returned when tyring to create_contact_obj(): {create_contact_obj_result}')
contact_id = None
@@ -337,6 +340,8 @@ def create_person_obj(person_obj_new:Person_Base):
# ### BEGIN ### API Person Methods ### update_person_obj() ###
# NOTE: This will update a person and then also create or update 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. The update_contact_obj will update a contact and then also create or update a linked address if person_obj.contact.address data is passed.
# Reviewed and updated 2021-08-10
def update_person_obj(
person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
person_obj_up: Person_Base,
@@ -376,7 +381,9 @@ def update_person_obj(
if contact_obj_in_result := create_contact_obj(contact_obj_new=contact_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(contact_obj_in_result)
person_obj_up.contact_id = contact_obj_in_result
# NOTE: This last update should no longer be needed now that the person.contact_id is not supposed to be used.
# Need to update the person with the new contact_id
person_obj_up.contact_id = contact_obj_in_result # REMOVE
else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(contact_obj_in_result)
@@ -403,6 +410,7 @@ def update_person_obj(
if organization_obj_in_result := create_organization_obj(organization_obj_new=organization_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(organization_obj_in_result)
# Need to update the person with the new organization_id
person_obj_up.organization_id = organization_obj_in_result
else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
@@ -431,6 +439,7 @@ def update_person_obj(
if user_obj_in_result := create_user_obj(user_obj_new=user_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(user_obj_in_result)
# Need to update the person with the new user_id
person_obj_up.user_id = user_obj_in_result
else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL