Code clean up. Simplifying person, user, contact, and address methods
This commit is contained in:
@@ -231,7 +231,7 @@ def create_address_obj(
|
|||||||
for_id: int|str = None,
|
for_id: int|str = None,
|
||||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||||
) -> int|bool:
|
) -> 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())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
@@ -312,7 +312,7 @@ def update_address_obj(
|
|||||||
create_sub_obj: bool = False,
|
create_sub_obj: bool = False,
|
||||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||||
) -> bool:
|
) -> bool:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
@@ -326,7 +326,6 @@ def update_address_obj(
|
|||||||
address_dict = address_dict_obj
|
address_dict = address_dict_obj
|
||||||
try:
|
try:
|
||||||
address_obj = Contact_Base(**address_dict)
|
address_obj = Contact_Base(**address_dict)
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(address_obj)
|
log.debug(address_obj)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
@@ -338,7 +337,7 @@ def update_address_obj(
|
|||||||
|
|
||||||
# ### SECTION ### Process data
|
# ### SECTION ### Process data
|
||||||
address_obj.id = address_id # Is this needed?
|
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)
|
||||||
# log.debug(address_dict_obj.dict(by_alias=True, exclude_unset=True))
|
# log.debug(address_dict_obj.dict(by_alias=True, exclude_unset=True))
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ def create_contact_obj(
|
|||||||
create_sub_obj: bool = False,
|
create_sub_obj: bool = False,
|
||||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||||
) -> int|bool:
|
) -> 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())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### 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
|
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||||
return_dict: bool = False,
|
return_dict: bool = False,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
@@ -465,7 +465,6 @@ def update_contact_obj(
|
|||||||
contact_dict = contact_dict_obj
|
contact_dict = contact_dict_obj
|
||||||
try:
|
try:
|
||||||
contact_obj = Contact_Base(**contact_dict)
|
contact_obj = Contact_Base(**contact_dict)
|
||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
||||||
log.debug(contact_obj)
|
log.debug(contact_obj)
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
log.error(e.json())
|
log.error(e.json())
|
||||||
@@ -477,7 +476,7 @@ def update_contact_obj(
|
|||||||
|
|
||||||
# ### SECTION ### Process data
|
# ### SECTION ### Process data
|
||||||
contact_obj.id = contact_id # Is this needed?
|
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)
|
account_id = get_account_id_w_contact_id(contact_id)
|
||||||
|
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ def update_person_kiss(
|
|||||||
|
|
||||||
# ### SECTION ### Process data
|
# ### SECTION ### Process data
|
||||||
person_obj.id = person_id # Is this needed?
|
person_obj.id = person_id # Is this needed?
|
||||||
person_dict['person_id'] = person_id
|
person_dict['id'] = person_id
|
||||||
|
|
||||||
if user_id:
|
if user_id:
|
||||||
# Link to an existing user
|
# Link to an existing user
|
||||||
@@ -799,6 +799,7 @@ def create_update_person_obj_v4b(
|
|||||||
if update_user_obj_result := update_user_obj(
|
if update_user_obj_result := update_user_obj(
|
||||||
user_id = user_id,
|
user_id = user_id,
|
||||||
user_dict_obj = user_obj,
|
user_dict_obj = user_obj,
|
||||||
|
person_id = person_id,
|
||||||
# create_sub_obj = create_sub_obj,
|
# create_sub_obj = create_sub_obj,
|
||||||
# fail_any = fail_any,
|
# fail_any = fail_any,
|
||||||
):
|
):
|
||||||
@@ -819,6 +820,7 @@ def create_update_person_obj_v4b(
|
|||||||
if create_user_obj_result := create_user_obj(
|
if create_user_obj_result := create_user_obj(
|
||||||
account_id = account_id,
|
account_id = account_id,
|
||||||
user_dict_obj = user_obj,
|
user_dict_obj = user_obj,
|
||||||
|
person_id = person_id,
|
||||||
# create_sub_obj = create_sub_obj,
|
# create_sub_obj = create_sub_obj,
|
||||||
# fail_any = fail_any,
|
# fail_any = fail_any,
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
|||||||
def create_user_obj(
|
def create_user_obj(
|
||||||
account_id: int|str,
|
account_id: int|str,
|
||||||
user_dict_obj: User_New_Base,
|
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
|
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
|
avoid_dup_username: bool = False, # Avoid creating a duplicate by modifying the supplied username
|
||||||
create_sub_obj: bool = False,
|
create_sub_obj: bool = False,
|
||||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||||
return_dict: bool = False,
|
return_dict: bool = False,
|
||||||
) -> bool|dict|int:
|
) -> 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())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
@@ -147,12 +147,12 @@ def create_user_obj(
|
|||||||
def update_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_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.
|
||||||
user_dict_obj: User_Base,
|
user_dict_obj: User_Base,
|
||||||
person_id: int,
|
person_id: int = None, # This should be required in the future?
|
||||||
create_sub_obj: bool = False,
|
create_sub_obj: bool = False,
|
||||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||||
return_dict: bool = False,
|
return_dict: bool = False,
|
||||||
) -> bool|int:
|
) -> 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())
|
log.debug(locals())
|
||||||
|
|
||||||
# ### SECTION ### Secondary data validation
|
# ### SECTION ### Secondary data validation
|
||||||
@@ -274,7 +274,7 @@ def update_user_obj(
|
|||||||
|
|
||||||
# ### SECTION ### Process data
|
# ### SECTION ### Process data
|
||||||
user_obj.id = user_id # Is this needed?
|
user_obj.id = user_id # Is this needed?
|
||||||
user_dict['user_id'] = user_id
|
user_dict['id'] = user_id
|
||||||
|
|
||||||
if person_id:
|
if person_id:
|
||||||
# Link to an existing person
|
# Link to an existing person
|
||||||
|
|||||||
@@ -223,11 +223,12 @@ async def user_authenticate(
|
|||||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if account_id and username and password:
|
account_id = commons.x_account_id
|
||||||
account_id = commons.x_account_id
|
|
||||||
|
|
||||||
|
if username and password:
|
||||||
user_data = {}
|
user_data = {}
|
||||||
user_data['account_id'] = account_id
|
if not null_account_id: user_data['account_id'] = account_id
|
||||||
|
else: user_data['account_id'] = None
|
||||||
user_data['username'] = username
|
user_data['username'] = username
|
||||||
|
|
||||||
# sql_select(table_name='user', data=user_data)
|
# sql_select(table_name='user', data=user_data)
|
||||||
@@ -631,14 +632,14 @@ async def lookup_email(
|
|||||||
data['account_id'] = account_id
|
data['account_id'] = account_id
|
||||||
data['email'] = email
|
data['email'] = email
|
||||||
|
|
||||||
if enabled in ['enabled', 'disabled', 'all']:
|
if commons.enabled in ['enabled', 'disabled', 'all']:
|
||||||
if enabled == 'enabled':
|
if commons.enabled == 'enabled':
|
||||||
data['enable'] = True
|
data['enable'] = True
|
||||||
sql_enabled = f'AND `user`.enable = :enable'
|
sql_enabled = f'AND `user`.enable = :enable'
|
||||||
elif enabled == 'disabled':
|
elif commons.enabled == 'disabled':
|
||||||
data['enable'] = False
|
data['enable'] = False
|
||||||
sql_enabled = f'AND `user`.enable = :enable'
|
sql_enabled = f'AND `user`.enable = :enable'
|
||||||
elif enabled == 'all':
|
elif commons.enabled == 'all':
|
||||||
sql_enabled = ''
|
sql_enabled = ''
|
||||||
else:
|
else:
|
||||||
return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request
|
return mk_resp(data=None, status_code=400, response=commons.response) # Bad Request
|
||||||
|
|||||||
Reference in New Issue
Block a user