A lot of code clean up! Also adding in Response everywhere...
This commit is contained in:
@@ -99,6 +99,8 @@ def get_address_rec_list(
|
||||
|
||||
|
||||
# ### BEGIN ### API Address Methods ### create_address_obj() ###
|
||||
# NOTE: This will create an address.
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_address_obj(address_obj_new:Address_Base):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -122,6 +124,8 @@ def create_address_obj(address_obj_new:Address_Base):
|
||||
|
||||
|
||||
# ### BEGIN ### API Address Methods ### update_address_obj() ###
|
||||
# NOTE: This will update an address.
|
||||
# Reviewed and updated 2021-08-10
|
||||
def update_address_obj(
|
||||
address_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
address_obj_up: Address_Base,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -22,31 +22,6 @@ from app.methods.user_methods import create_user_obj, load_user_obj, update_user
|
||||
from app.models.event_person_models import Event_Person_New_Base, Event_Person_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
||||
def create_event_person_obj(event_person_obj_new:Event_Person_Base) -> int|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if not event_person_obj_new:
|
||||
return False
|
||||
|
||||
event_person_obj_data = event_person_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'created_on', 'updated_on'})
|
||||
log.debug(event_person_obj_data)
|
||||
|
||||
if event_person_obj_in_result := sql_insert(data=event_person_obj_data, table_name='event_person', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
return False
|
||||
|
||||
#log.setLevel(logging.DEBUG)
|
||||
log.debug(event_person_obj_in_result)
|
||||
|
||||
event_person_id = event_person_obj_in_result
|
||||
|
||||
log.debug(f'Returning the new event_person_id: {event_person_id}')
|
||||
return event_person_id
|
||||
# ### END ### API Event Person Methods ### create_event_person_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### load_event_person_obj() ###
|
||||
def load_event_person_obj(
|
||||
event_person_id: int|str,
|
||||
@@ -132,7 +107,38 @@ def load_event_person_obj(
|
||||
# ### END ### API Event Person Methods ### load_event_person_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
||||
# NOTE: This will create an event_person. This event_person should include at least a person_id.
|
||||
# NOTE: Is it a good idea to create and or update a person and or user here??? The create_event_person_obj() below does do that.
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_event_person_obj(event_person_obj_new:Event_Person_Base) -> int|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if not event_person_obj_new:
|
||||
return False
|
||||
|
||||
event_person_obj_data = event_person_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'created_on', 'updated_on'})
|
||||
log.debug(event_person_obj_data)
|
||||
|
||||
if event_person_obj_in_result := sql_insert(data=event_person_obj_data, table_name='event_person', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
return False
|
||||
|
||||
#log.setLevel(logging.DEBUG)
|
||||
log.debug(event_person_obj_in_result)
|
||||
|
||||
event_person_id = event_person_obj_in_result
|
||||
|
||||
log.debug(f'Returning the new event_person_id: {event_person_id}')
|
||||
return event_person_id
|
||||
# ### END ### API Event Person Methods ### create_event_person_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Person Methods ### update_event_person_obj() ###
|
||||
# NOTE: This will update an event_person. This also tries to create or update a person or user if that data is passed.
|
||||
# NOTE: Is it a good idea to create and or update a person and or user here???
|
||||
# Reviewed and updated 2021-08-10
|
||||
def update_event_person_obj(
|
||||
event_person_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
event_person_obj_up: Event_Person_Base,
|
||||
|
||||
@@ -17,7 +17,7 @@ def load_order_cfg_obj(
|
||||
exclude_unset: bool = True,
|
||||
model_as_dict: bool = True,
|
||||
) -> Order_Cfg_Base|dict|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
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
|
||||
|
||||
@@ -122,6 +122,8 @@ def get_organization_rec_list(
|
||||
|
||||
|
||||
# ### BEGIN ### API Organization Methods ### update_organization_obj() ###
|
||||
# NOTE: This will create an organization and then also create a linked contact if organization_obj.contact data is passed. The create_contact_obj will create a contact and then also create a linked address if organization_obj.contact.address data is passed.
|
||||
# Reviewed and updated 2021-08-10
|
||||
def update_organization_obj(
|
||||
organization_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||
organization_obj_up: Organization_Base,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,9 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API User Methods ### create_user_obj() ###
|
||||
# NOTE: This will create a new user and also hash a new password string if given.
|
||||
# NOTE: This uses the User_New_Base model, not User_Base or User_Out_Base
|
||||
# Reviewed and updated 2021-08-10
|
||||
def create_user_obj(user_obj_new:User_New_Base) -> int|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
@@ -27,8 +30,6 @@ def create_user_obj(user_obj_new:User_New_Base) -> int|bool:
|
||||
return False
|
||||
|
||||
# user_obj_data = user_obj_new.dict(by_alias=False, exclude_defaults=False, include={'password'}, exclude={'new_password'})
|
||||
# log.debug(user_obj_data)
|
||||
|
||||
user_obj_data = user_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'new_password'})
|
||||
log.debug(user_obj_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user