Work on event files and event location and related
This commit is contained in:
@@ -43,8 +43,15 @@ def load_event_location_obj(
|
||||
if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
|
||||
else: return False
|
||||
|
||||
if event_location_rec := sql_select(table_name='v_event_location', record_id=event_location_id): pass
|
||||
else: return False
|
||||
if inc_file_count:
|
||||
log.info('Using view with file count')
|
||||
if event_location_rec := sql_select(table_name='v_event_location_w_file_count', record_id=event_location_id): pass
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
if event_location_rec := sql_select(table_name='v_event_location', record_id=event_location_id): pass
|
||||
else:
|
||||
return False
|
||||
|
||||
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_location_rec)
|
||||
@@ -267,3 +274,130 @@ def get_event_location_rec_list(
|
||||
|
||||
return event_location_rec_li
|
||||
# ### END ### API Event Location Methods ### get_event_location_rec_list() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Location Methods ### create_update_event_location_obj_v4() ###
|
||||
# NOTE: This will create or update a event_location.
|
||||
# Rewrite and updated 2021-08-25
|
||||
def create_update_event_location_obj_v4(
|
||||
event_location_dict_obj: Event_Location_Base|dict,
|
||||
event_location_id: int|str = None,
|
||||
event_id: int|str = None,
|
||||
# event_location_id: int|str = None, # For future?
|
||||
# event_track_id: int|str = None, # For future?
|
||||
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_location_id:
|
||||
log.info(f'Event Location ID passed. Update existing Event Location. Event Location ID: {event_location_id}')
|
||||
|
||||
if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
|
||||
else:
|
||||
log.error('Event Location 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_location', for_id=event_location_id): pass
|
||||
else:
|
||||
log.error('Unable to get Event ID from related object.')
|
||||
False
|
||||
else:
|
||||
log.info('No Event Location ID passed. Create new Event Location. 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
|
||||
|
||||
log.debug(type(event_location_dict_obj))
|
||||
if isinstance(event_location_dict_obj, dict):
|
||||
event_location_dict = event_location_dict_obj
|
||||
if event_location_id:
|
||||
event_location_dict['event_location_id'] = event_location_id
|
||||
if event_id:
|
||||
event_location_dict['event_id'] = event_id
|
||||
try:
|
||||
event_location_obj = Event_Location_Base(**event_location_dict)
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(event_location_obj)
|
||||
except ValidationError as e:
|
||||
log.error(e.json())
|
||||
return False
|
||||
else:
|
||||
event_location_obj = event_location_dict_obj
|
||||
if event_location_id:
|
||||
# NOTE: Can't update the ID alias if it was never set.
|
||||
event_location_obj.id = event_location_id
|
||||
if event_id:
|
||||
event_location_obj.event_id = event_id
|
||||
|
||||
event_location_dict = event_location_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'event_presentation', 'event_presentation_list', 'created_on', 'updated_on'})
|
||||
|
||||
if event_location_id:
|
||||
if event_location_dict_up_result := sql_update(data=event_location_dict, table_name='event_location', rm_id_random=True): pass
|
||||
else:
|
||||
log.warning(f'Event Location not updated. Event Location ID: {event_location_id}')
|
||||
log.debug(event_location_dict_up_result)
|
||||
return False
|
||||
log.debug(event_location_dict_up_result)
|
||||
else:
|
||||
if event_location_dict_in_result := sql_insert(data=event_location_dict, table_name='event_location', rm_id_random=True, id_random_length=8): pass
|
||||
else:
|
||||
log.warning(f'Event Location not created.')
|
||||
log.debug(event_location_dict_in_result)
|
||||
return False
|
||||
log.debug(event_location_dict_in_result)
|
||||
|
||||
event_location_id = event_location_dict_in_result
|
||||
|
||||
log.debug(event_location_id)
|
||||
|
||||
event_location_outline = {}
|
||||
event_location_outline['event_location_id'] = event_location_id
|
||||
event_location_outline['event_session_list'] = []
|
||||
|
||||
if event_location_obj.event_session_list and isinstance(event_location_obj.event_session_list, list):
|
||||
log.info(f'Event Session List was found. Loop through and create a new Event Session for each and link them to the new Event Location. Event Location ID: {event_location_id}')
|
||||
for event_session_obj in event_location_obj.event_session_list:
|
||||
# NOTE: Use object model version because of better type checking and validations
|
||||
log.debug(event_session_obj)
|
||||
if event_session_id := event_session_obj.id: pass
|
||||
else: event_session_id = None
|
||||
# event_session_obj.event_id = event_id
|
||||
# event_session_obj.event_location_id = event_location_id
|
||||
create_update_event_session_obj_result = create_update_event_session_obj_v4(
|
||||
event_session_dict_obj = event_session_obj,
|
||||
event_session_id = event_session_id,
|
||||
event_id = event_id,
|
||||
event_location_id = event_location_id,
|
||||
fail_any = fail_any,
|
||||
return_outline = return_outline,
|
||||
)
|
||||
if isinstance(create_update_event_session_obj_result, int):
|
||||
event_session_id = create_update_event_session_obj_result
|
||||
elif create_update_event_session_obj_result == True: pass
|
||||
else:
|
||||
log.warning(f'Create or Update failed while trying create_update_event_session_obj_v4(): {create_update_event_session_obj_result}')
|
||||
event_session_id = None
|
||||
|
||||
event_location_outline['event_session_id'] = event_session_id
|
||||
|
||||
if return_outline:
|
||||
log.debug(f'Returning the Event Location Outline: {event_location_outline}')
|
||||
return event_location_outline
|
||||
else:
|
||||
log.debug(f'Returning the Event Location ID: {event_location_id}')
|
||||
return event_location_id
|
||||
# ### END ### API Event Location Methods ### create_update_event_location_obj_v4() ###
|
||||
|
||||
@@ -571,7 +571,7 @@ def get_event_id_w_for_type_id(
|
||||
|
||||
sql = f"""
|
||||
SELECT `for`.id AS 'for_id', `for`.id_random AS 'for_id_random', `for`.event_id AS event_id
|
||||
FROM :for_type AS `for`
|
||||
FROM {for_type} AS `for`
|
||||
WHERE `for`.id = :for_id
|
||||
LIMIT 1;
|
||||
"""
|
||||
|
||||
@@ -383,7 +383,7 @@ def create_update_event_session_obj_v4(
|
||||
event_session_dict_obj: Event_Session_Base|dict,
|
||||
event_session_id: int|str = None,
|
||||
event_id: int|str = None,
|
||||
# event_location_id: int|str = None, # For future?
|
||||
event_location_id: int|str = None, # For future?
|
||||
# event_track_id: int|str = None, # For future?
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = False, # Fail if any thing goes wrong for sub objects
|
||||
@@ -478,15 +478,15 @@ def create_update_event_session_obj_v4(
|
||||
# event_presentation_obj.event_id = event_id
|
||||
# event_presentation_obj.event_session_id = event_session_id
|
||||
create_update_event_presentation_obj_result = create_update_event_presentation_obj_v4(
|
||||
event_presentation_dict_obj = event_presentation_obj,
|
||||
event_presentation_id = event_presentation_id,
|
||||
event_id = event_id,
|
||||
# event_location_id = event_location_id,
|
||||
event_session_id = event_session_id,
|
||||
# event_track_id = event_track_id,
|
||||
fail_any = fail_any,
|
||||
return_outline = return_outline,
|
||||
)
|
||||
event_presentation_dict_obj = event_presentation_obj,
|
||||
event_presentation_id = event_presentation_id,
|
||||
event_id = event_id,
|
||||
# event_location_id = event_location_id,
|
||||
event_session_id = event_session_id,
|
||||
# event_track_id = event_track_id,
|
||||
fail_any = fail_any,
|
||||
return_outline = return_outline,
|
||||
)
|
||||
if isinstance(create_update_event_presentation_obj_result, int):
|
||||
event_presentation_id = create_update_event_presentation_obj_result
|
||||
elif create_update_event_presentation_obj_result == True: pass
|
||||
|
||||
Reference in New Issue
Block a user