Code clean up and standardize

This commit is contained in:
Scott Idem
2021-08-25 11:16:02 -04:00
parent 1369874dc2
commit 8ff404e534
7 changed files with 21 additions and 13 deletions

View File

@@ -598,7 +598,7 @@ def update_event_obj(
# NOTE: This will blindly create a new user even if there was one associated but the event.user_id was not found.
user_obj_in = event_obj_up.user
log.debug(user_obj_in)
if user_obj_in_result := create_user_obj(user_obj_new=user_obj_in):
if user_obj_in_result := create_user_obj(account_id=account_id, user_obj_new=user_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(user_obj_in_result)
event_obj_up.user_id = user_obj_in_result

View File

@@ -632,7 +632,7 @@ def update_event_person_obj(
# NOTE: This will blindly create a new user even if there was one associated but the event_person.user_id was not found.
user_obj_in = event_person_obj_up.user
log.debug(user_obj_in)
if user_obj_in_result := create_user_obj(user_obj_new=user_obj_in):
if user_obj_in_result := create_user_obj(account_id=account_id, user_obj_new=user_obj_in):
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(user_obj_in_result)
event_person_obj_up.user_id = user_obj_in_result

View File

@@ -7,11 +7,7 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
from app.db_sql import redis_lookup_id_random, sql_insert, sql_insert_or_update, sql_select, sql_update
from app.lib_general import log, logging
# from app.methods.address_methods import load_address_obj
from app.methods.contact_methods import create_contact_obj, create_update_contact_obj, load_contact_obj, update_contact_obj
from app.methods.order_methods import load_order_obj, get_order_rec_list
from app.methods.organization_methods import create_update_organization_obj, load_organization_obj, update_organization_obj
# from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
# from app.methods.page_methods import load_page_obj, get_page_rec_list
from app.models.common_field_schema import default_num_bytes
from app.models.page_models import Page_Base

View File

@@ -649,7 +649,7 @@ def create_person_obj_v3(
# Updated 2021-08-24
def update_person_obj_v3(
person_id: int|str,
person_obj_exist: Event_Person_Base,
person_obj_exist: Person_Base,
create_sub_obj: bool = False,
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
) -> bool:
@@ -659,6 +659,8 @@ def update_person_obj_v3(
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: return False
account_id = get_account_id_w_person_id(person_id=person_id)
# Can't update the person_id alias if the .id was never set.
# person_obj_exist.person_id = person_id
if not person_obj_exist.id:
@@ -823,7 +825,7 @@ def update_person_obj_v3(
log.info(f'No User ID found.')
# from app.methods.user_methods import create_user_obj_v3
if create_user_obj_result := create_user_obj(
person_id = person_id,
account_id = account_id,
user_obj_new = user_obj_unknown,
create_sub_obj = create_sub_obj,
fail_any = fail_any,
@@ -867,6 +869,8 @@ def update_person_obj(
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
else: return False
account_id = get_account_id_w_person_id(person_id=person_id)
person_obj_up.id = person_id
log.debug(person_obj_up)
@@ -950,7 +954,7 @@ def update_person_obj(
# NOTE: This will blindly create a new user even if there was one associated but the person.user_id was not found.
user_obj_in = person_obj_up.user
log.debug(user_obj_in)
if user_obj_in_result := create_user_obj(user_obj_new=user_obj_in):
if user_obj_in_result := create_user_obj(account_id=account_id, 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

View File

@@ -24,6 +24,7 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
# Reviewed and updated 2021-08-21
# Reviewed and updated 2021-08-10
def create_user_obj(
account_id: int|str,
user_obj_new: User_New_Base,
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
@@ -38,7 +39,11 @@ def create_user_obj(
user_obj_data['password'] = user_obj_new.password # There has to be a better way to do this??? It thinks "password" is unset and so is excluded?
log.debug(user_obj_data)
account_id = user_obj_data.get('account_id', None)
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
elif account_id := user_obj_data.get('account_id', None): pass
else: return False
# account_id = user_obj_data.get('account_id', None)
username = user_obj_data.get('username', None)
log.info(f'Checking if the username is already in use for the account... Account: {account_id} Username: {username}')