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
|
||||
|
||||
@@ -9,7 +9,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_location_methods import get_event_location_rec_list, load_event_location_obj
|
||||
from app.methods.event_location_methods import create_update_event_location_obj_v4, get_event_location_rec_list, load_event_location_obj
|
||||
|
||||
from app.models.event_location_models import Event_Location_Base
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
@@ -18,6 +18,64 @@ from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Location ### patch_event_location_obj_exist_v4() ###
|
||||
# Updated 2021-10-22
|
||||
@router.patch('/event/location/{event_location_id}/exist_v4', response_model=Resp_Body_Base)
|
||||
async def patch_event_location_obj_exist_v4(
|
||||
event_location_obj: Event_Location_Base,
|
||||
event_location_id: str = Query(..., min_length=11, max_length=22),
|
||||
create_sub_obj: bool = False,
|
||||
fail_any: bool = True, # Fail if any thing goes wrong for sub objects
|
||||
|
||||
inc_event_file_list: bool = False,
|
||||
inc_event_presentation_list: bool = False,
|
||||
inc_event_presenter_list: bool = False,
|
||||
inc_event_session_list: bool = False,
|
||||
|
||||
x_account_id: Optional[str] = Header(..., ),
|
||||
return_obj: Optional[bool] = True,
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
exclude_none: Optional[bool] = True,
|
||||
response: Response = Response,
|
||||
):
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if event_location_id := redis_lookup_id_random(record_id_random=event_location_id, table_name='event_location'): pass
|
||||
else: return mk_resp(data=None, status_code=404, response=response)
|
||||
|
||||
if update_event_location_obj_result := create_update_event_location_obj_v4(
|
||||
event_location_dict_obj = event_location_obj,
|
||||
event_location_id = event_location_id,
|
||||
event_id = event_location_obj.event_id,
|
||||
create_sub_obj = create_sub_obj,
|
||||
fail_any = fail_any,
|
||||
return_outline = False,
|
||||
): pass
|
||||
else: return mk_resp(data=False, status_code=400, response=response, status_message='The event location was not created. Check the field names and data types.')
|
||||
|
||||
if update_event_location_obj_result:
|
||||
if return_obj:
|
||||
if load_event_location_obj_result := load_event_location_obj(
|
||||
event_location_id = event_location_id,
|
||||
inc_event_file_list = inc_event_file_list,
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
inc_event_presenter_list = inc_event_presenter_list,
|
||||
inc_event_session_list = inc_event_session_list,
|
||||
):
|
||||
data = load_event_location_obj_result
|
||||
else:
|
||||
data = False
|
||||
else:
|
||||
event_location_id_random = get_id_random(record_id=event_location_id, table_name='event_location')
|
||||
data = {}
|
||||
data['event_location_id'] = event_location_id
|
||||
data['event_location_id_random'] = event_location_id_random
|
||||
return mk_resp(data=data, response=response, status_message='The event location was created.')
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message='The result from trying to create an event location was unexpected.')
|
||||
# ### END ### API Event Location ### patch_event_location_obj_exist_v4() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Event Location ### get_event_location_obj() ###
|
||||
@@ -29,6 +87,7 @@ async def get_event_location_obj(
|
||||
inc_event_presentation_list: bool = False,
|
||||
inc_event_presenter_list: bool = False,
|
||||
inc_event_session_list: bool = False,
|
||||
inc_file_count: bool = False, # NOTE: file counts are from separate views
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
limit: int = 500,
|
||||
@@ -49,6 +108,7 @@ async def get_event_location_obj(
|
||||
inc_event_presentation_list = inc_event_presentation_list,
|
||||
inc_event_presenter_list = inc_event_presenter_list,
|
||||
inc_event_session_list = inc_event_session_list,
|
||||
inc_file_count = inc_file_count,
|
||||
enabled = enabled,
|
||||
hidden = hidden,
|
||||
limit = limit,
|
||||
|
||||
Reference in New Issue
Block a user