Working on creating a person with related objects.
This commit is contained in:
@@ -53,7 +53,7 @@ def load_person_obj(
|
||||
inc_product: bool = False,
|
||||
inc_user: bool = False,
|
||||
) -> Person_Base|bool:
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if person_id := redis_lookup_id_random(record_id_random=person_id, table_name='person'): pass
|
||||
@@ -64,6 +64,7 @@ def load_person_obj(
|
||||
|
||||
try:
|
||||
person_obj = Person_Base(**person_rec)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
|
||||
@@ -20,7 +20,7 @@ from app.models.user_models import User_Base, User_New_Base, User_Out_Base
|
||||
|
||||
# ### BEGIN ### API User Methods ### create_user_obj() ###
|
||||
def create_user_obj(user_obj_new:User_New_Base) -> int|bool:
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if not user_obj_new:
|
||||
@@ -62,7 +62,7 @@ def create_user_obj(user_obj_new:User_New_Base) -> int|bool:
|
||||
else:
|
||||
return False
|
||||
|
||||
#log.setLevel(logging.DEBUG)
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(user_obj_in_result)
|
||||
|
||||
user_id = user_obj_in_result
|
||||
|
||||
@@ -75,7 +75,7 @@ class Person_Base(BaseModel):
|
||||
order_cart_list: Optional[list] # Order_Base() # Priority l2
|
||||
organization: Optional[Union[Organization_Base, None]]
|
||||
post_list: Optional[list] # Post_Base() # Priority l1
|
||||
# user: Optional[Union[User_Base, None]]
|
||||
user: Optional[dict] # Optional[Union[User_Base, None]]
|
||||
|
||||
_processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select,
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.event_person_methods import create_event_person_obj, load_event_person_obj, update_event_person_obj
|
||||
from app.methods.person_methods import create_person_obj, load_person_obj
|
||||
from app.methods.person_methods import create_person_obj, load_person_obj, update_person_obj
|
||||
from app.methods.user_methods import create_user_obj, load_user_obj, update_user_obj
|
||||
# from app.methods.user_load_methods import load_user_obj
|
||||
|
||||
@@ -43,7 +43,7 @@ async def post_event_person_new(
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
account_id_random = event_person_new_init.account_id_random
|
||||
@@ -92,11 +92,12 @@ async def post_event_person_new(
|
||||
if isinstance(create_person_obj_result, int):
|
||||
person_id = create_person_obj_result
|
||||
person_obj = load_person_obj(
|
||||
person_id=person_id,
|
||||
inc_contact=True,
|
||||
inc_address=True,
|
||||
inc_organization=True
|
||||
person_id = person_id,
|
||||
inc_contact = True,
|
||||
inc_address = True,
|
||||
inc_organization = True,
|
||||
)
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(person_obj)
|
||||
else:
|
||||
log.debug('A new person was not created')
|
||||
@@ -112,9 +113,15 @@ async def post_event_person_new(
|
||||
user_new['contact_id_random'] = person_obj.contact.id_random
|
||||
user_new['person_id_random'] = person_obj.id_random
|
||||
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_new)
|
||||
|
||||
user_obj_new = User_New_Base(**user_new)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj_new)
|
||||
|
||||
user_id = None
|
||||
user_obj = None
|
||||
create_user_obj_result = create_user_obj(user_obj_new=user_obj_new)
|
||||
if isinstance(create_user_obj_result, bool):
|
||||
log.debug('Returning False since multiple users were found with the same username.')
|
||||
@@ -122,11 +129,38 @@ async def post_event_person_new(
|
||||
elif isinstance(create_user_obj_result, int):
|
||||
user_id = create_user_obj_result
|
||||
user_obj = load_user_obj(user_id=user_id) # Not including roles, contact, or organization
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(user_obj)
|
||||
else:
|
||||
log.debug('A new user was not created')
|
||||
return mk_resp(data=False)
|
||||
|
||||
# Update person with new user ID
|
||||
person_data_update = {}
|
||||
# person_data_update['user_id'] = user_id
|
||||
person_data_update['user_id_random'] = user_obj.id_random
|
||||
|
||||
person_obj_update = Person_Base(**person_data_update)
|
||||
log.debug(person_obj_update)
|
||||
|
||||
person_obj_update_result = update_person_obj(
|
||||
person_id = person_id,
|
||||
person_obj_up = person_obj_update
|
||||
)
|
||||
if person_obj_update_result:
|
||||
log.debug('The new person was updated with the user ID')
|
||||
# person_id = person_obj_update_result
|
||||
# person_obj = load_person_obj(
|
||||
# person_id = person_id,
|
||||
# inc_contact = True,
|
||||
# inc_address = True,
|
||||
# inc_organization = True,
|
||||
# )
|
||||
log.debug(person_obj_update_result)
|
||||
else:
|
||||
log.debug('A new person was not updated')
|
||||
return mk_resp(data=False)
|
||||
|
||||
# New event person
|
||||
event_person_new = {}
|
||||
event_person_new['account_id_random'] = account_id_random
|
||||
|
||||
Reference in New Issue
Block a user