Working on creating a person with related objects.
This commit is contained in:
@@ -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