Code clean up. Simplifying person, user, contact, and address methods

This commit is contained in:
Scott Idem
2022-01-06 13:47:23 -05:00
parent 567f6a6302
commit c01e668d9e
5 changed files with 22 additions and 21 deletions

View File

@@ -231,7 +231,7 @@ def create_address_obj(
for_id: int|str = None,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> int|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -312,7 +312,7 @@ def update_address_obj(
create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -326,7 +326,6 @@ def update_address_obj(
address_dict = address_dict_obj
try:
address_obj = Contact_Base(**address_dict)
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(address_obj)
except ValidationError as e:
log.error(e.json())
@@ -338,7 +337,7 @@ def update_address_obj(
# ### SECTION ### Process data
address_obj.id = address_id # Is this needed?
address_dict['address_id'] = address_id
address_dict['id'] = address_id
log.debug(address_dict_obj)
# log.debug(address_dict_obj.dict(by_alias=True, exclude_unset=True))

View File

@@ -322,7 +322,7 @@ def create_contact_obj(
create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> int|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -451,7 +451,7 @@ def update_contact_obj(
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
return_dict: bool = False,
) -> bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -465,7 +465,6 @@ def update_contact_obj(
contact_dict = contact_dict_obj
try:
contact_obj = Contact_Base(**contact_dict)
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(contact_obj)
except ValidationError as e:
log.error(e.json())
@@ -477,7 +476,7 @@ def update_contact_obj(
# ### SECTION ### Process data
contact_obj.id = contact_id # Is this needed?
contact_dict['contact_id'] = contact_id
contact_dict['id'] = contact_id
account_id = get_account_id_w_contact_id(contact_id)

View File

@@ -570,7 +570,7 @@ def update_person_kiss(
# ### SECTION ### Process data
person_obj.id = person_id # Is this needed?
person_dict['person_id'] = person_id
person_dict['id'] = person_id
if user_id:
# Link to an existing user
@@ -799,6 +799,7 @@ def create_update_person_obj_v4b(
if update_user_obj_result := update_user_obj(
user_id = user_id,
user_dict_obj = user_obj,
person_id = person_id,
# create_sub_obj = create_sub_obj,
# fail_any = fail_any,
):
@@ -819,6 +820,7 @@ def create_update_person_obj_v4b(
if create_user_obj_result := create_user_obj(
account_id = account_id,
user_dict_obj = user_obj,
person_id = person_id,
# create_sub_obj = create_sub_obj,
# fail_any = fail_any,
):

View File

@@ -27,14 +27,14 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
def create_user_obj(
account_id: int|str,
user_dict_obj: User_New_Base,
person_id: int,
person_id: int = None, # This should be required in the future
allow_update: bool = False, # Allow updating the user account if one is found
avoid_dup_username: bool = False, # Avoid creating a duplicate by modifying the supplied username
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
return_dict: bool = False,
) -> bool|dict|int:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -147,12 +147,12 @@ def create_user_obj(
def update_user_obj(
user_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
user_dict_obj: User_Base,
person_id: int,
person_id: int = None, # This should be required in the future?
create_sub_obj: bool = False,
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
return_dict: bool = False,
) -> bool|int:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# ### SECTION ### Secondary data validation
@@ -274,7 +274,7 @@ def update_user_obj(
# ### SECTION ### Process data
user_obj.id = user_id # Is this needed?
user_dict['user_id'] = user_id
user_dict['id'] = user_id
if person_id:
# Link to an existing person