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

@@ -116,6 +116,8 @@ def get_contact_rec_list(
# ### BEGIN ### API Contact Methods ### create_contact_obj() ###
# NOTE: This will create a contact and then also create a linked address if contact_obj.address data is passed.
# Reviewed and updated 2021-08-10
def create_contact_obj(contact_obj_new:Contact_Base):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -140,14 +142,15 @@ def create_contact_obj(contact_obj_new:Contact_Base):
create_address_obj_result = create_address_obj(address_obj_new=address_obj_new)
if isinstance(create_address_obj_result, int):
address_id = create_address_obj_result
# NOTE: This last update should no longer be needed now that the contact.address_id is not supposed to be used.
# Need to update the contact with the new address_id
contact_obj_up = {}
contact_obj_up['id'] = contact_id
contact_obj_up['address_id'] = address_id
if contact_obj_up_result := sql_update(data=contact_obj_up, table_name='contact'): pass
else:
return False
log.debug(contact_obj_up_result)
contact_obj_up = {} # REMOVE
contact_obj_up['id'] = contact_id # REMOVE
contact_obj_up['address_id'] = address_id # REMOVE
if contact_obj_up_result := sql_update(data=contact_obj_up, table_name='contact'): pass # REMOVE
else: # REMOVE
return False # REMOVE
log.debug(contact_obj_up_result) # REMOVE
else:
log.debug(f'No address_id was returned when tyring to create_address_obj(): {create_address_obj_result}')
address_id = None
@@ -158,6 +161,8 @@ def create_contact_obj(contact_obj_new:Contact_Base):
# ### BEGIN ### API Contact Methods ### update_contact_obj() ###
# NOTE: This will update a contact and then also create or update a linked address if contact_obj.address data is passed.
# Reviewed and updated 2021-08-10
def update_contact_obj(
contact_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
contact_obj_up: Contact_Base,
@@ -199,7 +204,9 @@ def update_contact_obj(
if address_obj_in_result := create_address_obj(address_obj_new=address_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(address_obj_in_result)
contact_obj_up.address_id = address_obj_in_result
# NOTE: This last update should no longer be needed now that the contact.address_id is not supposed to be used.
# Need to update the contact with the new address_id
contact_obj_up.address_id = address_obj_in_result # REMOVE
else:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(address_obj_in_result)