Code clean up. Simplifying person, user, contact, and address methods
This commit is contained in:
@@ -23,9 +23,7 @@ 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
|
||||
# Updated 2021-08-25
|
||||
# Reviewed and updated 2021-08-21
|
||||
# Reviewed and updated 2021-08-10
|
||||
# Updated 2022-01-06
|
||||
def create_user_obj(
|
||||
account_id: int|str,
|
||||
user_dict_obj: User_New_Base,
|
||||
@@ -49,7 +47,7 @@ def create_user_obj(
|
||||
if isinstance(user_dict_obj, dict):
|
||||
user_dict = user_dict_obj
|
||||
try:
|
||||
user_obj = Person_Base(**user_dict)
|
||||
user_obj = User_New_Base(**user_dict)
|
||||
log.debug(user_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
@@ -167,8 +165,7 @@ def update_user_obj(
|
||||
if isinstance(user_dict_obj, dict):
|
||||
user_dict = user_dict_obj
|
||||
try:
|
||||
user_obj = Person_Base(**user_dict)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
user_obj = User_Base(**user_dict)
|
||||
log.debug(user_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
@@ -180,19 +177,19 @@ def update_user_obj(
|
||||
user_dict = user_obj.dict(by_alias=False, exclude_unset=True, exclude={'password', 'super', 'manager', 'contact', 'organization', 'person', 'created_on', 'updated_on'})
|
||||
|
||||
|
||||
log.debug(type(user_dict_obj))
|
||||
if isinstance(user_dict_obj, dict):
|
||||
try:
|
||||
user_obj = User_Base(**user_dict_obj)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
# log.debug(type(user_dict_obj))
|
||||
# if isinstance(user_dict_obj, dict):
|
||||
# try:
|
||||
# user_obj = User_Base(**user_dict_obj)
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(user_obj)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
# return False
|
||||
|
||||
user_obj.id = user_id
|
||||
# user_obj.id = user_id
|
||||
|
||||
log.debug(user_obj)
|
||||
# log.debug(user_obj)
|
||||
# log.debug(user_obj.dict(by_alias=True, exclude_unset=True))
|
||||
log.debug(user_obj.dict(by_alias=False, exclude_unset=True))
|
||||
# log.debug(user_obj.dict(by_alias=False, exclude_unset=False))
|
||||
@@ -204,7 +201,7 @@ def update_user_obj(
|
||||
# log.debug(contact_obj_up)
|
||||
# if contact_obj_up_result := update_contact_obj(
|
||||
# contact_id=contact_id,
|
||||
# contact_obj_up=contact_obj_up,
|
||||
# contact_dict_obj=contact_obj_up,
|
||||
# create_sub_obj=create_sub_obj,
|
||||
# ):
|
||||
# log.debug(contact_obj_up_result)
|
||||
@@ -215,7 +212,7 @@ def update_user_obj(
|
||||
# # NOTE: This will blindly create a new contact even if there was one associated but the user.contact_id was not found.
|
||||
# contact_obj_in = user_obj.contact
|
||||
# log.debug(contact_obj_in)
|
||||
# if contact_obj_in_result := create_contact_obj(contact_obj_new=contact_obj_in):
|
||||
# if contact_obj_in_result := create_contact_obj(contact_dict_obj=contact_obj_in):
|
||||
# # log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(contact_obj_in_result)
|
||||
# user_obj.contact_id = contact_obj_in_result
|
||||
@@ -276,7 +273,7 @@ def update_user_obj(
|
||||
# log.debug(user_dict)
|
||||
|
||||
# ### SECTION ### Process data
|
||||
user_obj.user_id = user_id # Is this needed?
|
||||
user_obj.id = user_id # Is this needed?
|
||||
user_dict['user_id'] = user_id
|
||||
|
||||
if person_id:
|
||||
|
||||
Reference in New Issue
Block a user