|
|
|
|
@@ -4,7 +4,7 @@ import datetime
|
|
|
|
|
from typing import Dict, List, Optional, Set, Union
|
|
|
|
|
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
|
|
|
|
|
|
|
|
|
from app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
|
|
|
|
from app.db_sql import get_account_id_w_for_type_id, redis_lookup_id_random, sql_insert, sql_select, sql_update
|
|
|
|
|
from app.lib_general import log, logging
|
|
|
|
|
|
|
|
|
|
# from app.methods.event_abstract_methods import load_event_abstract_obj
|
|
|
|
|
@@ -246,6 +246,163 @@ def get_event_id_w_event_person_id(
|
|
|
|
|
# ### END ### API Event Person Methods ### get_event_id_w_event_person_id() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Event Person Methods ### create_update_event_person_obj_v4() ###
|
|
|
|
|
# NOTE: This will create or update a event_person.
|
|
|
|
|
# Rewrite and updated 2021-08-25
|
|
|
|
|
def create_update_event_person_obj_v4(
|
|
|
|
|
event_person_dict_obj: Event_Person_Base|dict,
|
|
|
|
|
event_person_id: int|str = None,
|
|
|
|
|
account_id: int|str = None,
|
|
|
|
|
event_id: int|str = None,
|
|
|
|
|
create_sub_obj: bool = False,
|
|
|
|
|
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
|
|
|
|
return_outline: bool = False,
|
|
|
|
|
) -> int|bool:
|
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.debug(locals())
|
|
|
|
|
|
|
|
|
|
log.info('Checking requirements...')
|
|
|
|
|
if event_person_id:
|
|
|
|
|
log.info(f'Event Person ID passed. Update existing Event Person. Event Person ID: {event_person_id}')
|
|
|
|
|
|
|
|
|
|
if event_person_id := redis_lookup_id_random(record_id_random=event_person_id, table_name='event_person'): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Event Person ID passed but is invalid. Failed requirement.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Missing or invalid Event ID passed. Not required. Ignoring.')
|
|
|
|
|
log.info(f'Event ID: {event_id}')
|
|
|
|
|
|
|
|
|
|
log.info('Attempting to get Event ID from related object.')
|
|
|
|
|
from app.methods.event_methods import get_event_id_w_for_type_id
|
|
|
|
|
if event_id := get_event_id_w_for_type_id(for_type='event_person', for_id=event_person_id): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Unable to get Event ID from related object.')
|
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Missing or invalid Account ID passed. Not required. Ignoring.')
|
|
|
|
|
log.info(f'Account ID: {account_id}')
|
|
|
|
|
|
|
|
|
|
log.info('Attempting to get Account ID from related object.')
|
|
|
|
|
if account_id := get_account_id_w_for_type_id(for_type='event', for_id=event_id): pass
|
|
|
|
|
elif account_id := get_account_id_w_for_type_id(for_type='event_person', for_id=event_person_id): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Unable to get Account ID from related object.')
|
|
|
|
|
False
|
|
|
|
|
else:
|
|
|
|
|
log.info('No Event Person ID passed. Create new Event Person. Required: Account ID, Event ID')
|
|
|
|
|
|
|
|
|
|
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Missing or invalid Event ID passed. Failed requirement.')
|
|
|
|
|
log.info(f'Event ID: {event_id}')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Missing or invalid Account ID passed. Failed requirement.')
|
|
|
|
|
log.info(f'Account ID: {account_id}')
|
|
|
|
|
|
|
|
|
|
log.info('Attempting to get Account ID from related object.')
|
|
|
|
|
if account_id := get_account_id_w_for_type_id(for_type='event', for_id=event_id): pass
|
|
|
|
|
else:
|
|
|
|
|
log.error('Unable to get Account ID from related object.')
|
|
|
|
|
False
|
|
|
|
|
|
|
|
|
|
log.debug(type(event_person_dict_obj))
|
|
|
|
|
if isinstance(event_person_dict_obj, dict):
|
|
|
|
|
event_person_dict = event_person_dict_obj
|
|
|
|
|
if event_person_id:
|
|
|
|
|
event_person_dict['event_person_id'] = event_person_id
|
|
|
|
|
if account_id:
|
|
|
|
|
event_person_dict['account_id'] = account_id
|
|
|
|
|
if event_id:
|
|
|
|
|
event_person_dict['event_id'] = event_id
|
|
|
|
|
try:
|
|
|
|
|
event_person_obj = Event_Person_Base(**event_person_dict)
|
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
|
|
|
log.debug(event_person_obj)
|
|
|
|
|
except ValidationError as e:
|
|
|
|
|
log.error(e.json())
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
event_person_obj = event_person_dict_obj
|
|
|
|
|
if event_person_id:
|
|
|
|
|
# NOTE: Can't update the ID alias if it was never set.
|
|
|
|
|
event_person_obj.id = event_person_id
|
|
|
|
|
if account_id:
|
|
|
|
|
event_person_obj.account_id = account_id
|
|
|
|
|
if event_id:
|
|
|
|
|
event_person_obj.event_id = event_id
|
|
|
|
|
|
|
|
|
|
event_person_dict = event_person_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'event_badge', 'event_registration', 'created_on', 'updated_on'})
|
|
|
|
|
|
|
|
|
|
if event_person_id:
|
|
|
|
|
if event_person_dict_up_result := sql_update(data=event_person_dict, table_name='event_person', rm_id_random=True): pass
|
|
|
|
|
else:
|
|
|
|
|
log.warning(f'Event Person not updated. Event Person ID: {event_person_id}')
|
|
|
|
|
log.debug(event_person_dict_up_result)
|
|
|
|
|
return False
|
|
|
|
|
log.debug(event_person_dict_up_result)
|
|
|
|
|
else:
|
|
|
|
|
if event_person_dict_in_result := sql_insert(data=event_person_dict, table_name='event_person', rm_id_random=True, id_random_length=8): pass
|
|
|
|
|
else:
|
|
|
|
|
log.warning(f'Event Person not created.')
|
|
|
|
|
log.debug(event_person_dict_in_result)
|
|
|
|
|
return False
|
|
|
|
|
log.debug(event_person_dict_in_result)
|
|
|
|
|
|
|
|
|
|
event_person_id = event_person_dict_in_result
|
|
|
|
|
|
|
|
|
|
event_person_outline = {}
|
|
|
|
|
event_person_outline['event_person_id'] = event_person_id
|
|
|
|
|
|
|
|
|
|
# NOTE: WARNING: This has not been fully tested yet. 2021-08-25
|
|
|
|
|
# NOTE: Use object model version because of better type checking and validations
|
|
|
|
|
# if event_person_obj.event_badge:
|
|
|
|
|
# event_person_outline['event_badge_id'] = None
|
|
|
|
|
# event_badge_obj = event_person_obj.event_badge
|
|
|
|
|
# if event_badge_id := event_person_obj.event_badge_id: pass
|
|
|
|
|
# elif event_badge_id := event_badge_obj.id: pass
|
|
|
|
|
# else: event_badge_id = None
|
|
|
|
|
# event_badge_obj.id
|
|
|
|
|
# event_badge_obj.event_person_id = event_person_id
|
|
|
|
|
# create_update_event_badge_obj_result = create_update_event_badge_obj_v4(
|
|
|
|
|
# event_badge_dict_obj = event_badge_obj,
|
|
|
|
|
# event_badge_id = event_badge_id,
|
|
|
|
|
# # account_id = account_id,
|
|
|
|
|
# event_id = event_id,
|
|
|
|
|
# event_person_id = event_person_id,
|
|
|
|
|
# fail_any = fail_any,
|
|
|
|
|
# return_outline = return_outline,
|
|
|
|
|
# )
|
|
|
|
|
# if isinstance(create_update_event_badge_obj_result, int):
|
|
|
|
|
# event_badge_id = create_update_event_badge_obj_result
|
|
|
|
|
# elif create_update_event_badge_obj_result == True: pass
|
|
|
|
|
# else:
|
|
|
|
|
# log.warning(f'Create or Update failed while trying create_update_event_badge_obj_v4(): {create_update_event_badge_obj_result}')
|
|
|
|
|
# event_badge_id = None
|
|
|
|
|
|
|
|
|
|
# event_person_outline['event_badge_id'] = event_badge_id
|
|
|
|
|
|
|
|
|
|
if return_outline:
|
|
|
|
|
log.debug(f'Returning the Event Person Outline: {event_person_outline}')
|
|
|
|
|
return event_person_outline
|
|
|
|
|
else:
|
|
|
|
|
log.debug(f'Returning the Event Person ID: {event_person_id}')
|
|
|
|
|
return event_person_id
|
|
|
|
|
# ### END ### API Event Person Methods ### create_update_event_person_obj_v4() ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ### BEGIN ### API Event Person Methods ### create_event_person_obj() ###
|
|
|
|
|
# NOTE: This will create an event_person. This event_person should include at least a person_id.
|
|
|
|
|
# NOTE: Is it a good idea to create and or update a person and or user here??? The create_event_person_obj() below does do that.
|
|
|
|
|
|