General clean up. Work on abstracts and websockets

This commit is contained in:
Scott Idem
2023-03-23 19:12:13 -04:00
parent 430a155b75
commit 224aaed969
8 changed files with 435 additions and 48 deletions

View File

@@ -7,10 +7,10 @@ from app.db_sql import redis_lookup_id_random, sql_delete, sql_insert, sql_selec
from app.lib_general import log, logging, logger_reset
# from app.methods.event_abstract_tracking_methods import get_event_abstract_tracking_rec_list, load_event_abstract_tracking_obj
# from app.methods.event_person_methods import load_event_person_obj
from app.methods.event_person_methods import load_event_person_obj
from app.models.common_field_schema import default_num_bytes
from app.models.event_abstract_models import Event_Abstract_Base
from app.models.event_abstract_models import Event_Abstract_Ext, Event_Abstract_In
# ### BEGIN ### API Event Abstract Methods ### load_event_abstract_obj() ###
@@ -26,6 +26,7 @@ def load_event_abstract_obj(
inc_event_file_list: bool = False,
inc_event_person: bool = False,
inc_event_person_profile: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_list: bool = False,
inc_hosted_file: bool = False,
@@ -35,8 +36,8 @@ def load_event_abstract_obj(
by_alias: bool = True,
exclude_unset: bool = True,
model_as_dict: bool = False,
) -> Event_Abstract_Base|dict|bool:
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
) -> Event_Abstract_Ext|dict|bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
# if event_abstract_id := redis_lookup_id_random(record_id_random=event_abstract_id, table_name='event_abstract'): pass
@@ -46,7 +47,7 @@ def load_event_abstract_obj(
else: return False
try:
event_abstract_obj = Event_Abstract_Base(**event_abstract_rec)
event_abstract_obj = Event_Abstract_Ext(**event_abstract_rec)
log.debug(event_abstract_obj)
except ValidationError as e:
log.error(e.json())
@@ -99,7 +100,7 @@ def load_event_abstract_obj(
# inc_address = inc_address,
# inc_contact = inc_contact,
# inc_event_abstract = inc_event_abstract,
# inc_event_person_profile = inc_event_person_profile,
inc_event_person_profile = inc_event_person_profile,
# inc_event_registration = inc_event_registration,
# inc_person = inc_person,
# inc_user = inc_user,
@@ -226,10 +227,79 @@ def get_event_abstract_rec_list(
# ### BEGIN ### API Event Abstract Methods ### create_update_event_abstract_obj() ###
# Updated 2023-03-20
# Updated 2023-03-22
@logger_reset
def create_update_event_abstract_obj(
event_abstract_dict_obj: Event_Abstract_Base|dict,
event_abstract_obj: Event_Abstract_In,
event_abstract_id: int = None,
event_id: int = None,
event_person_id: int = 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_abstract_id:
log.info(f'Got: event_abstract_id={event_abstract_id}; Update existing Event Abstract')
event_abstract_obj.id = event_abstract_id
elif event_id and event_person_id:
log.info(f'Got: event_id={event_id}; event_person_id={event_person_id}; Create Event Abstract')
event_abstract_obj.event_id = event_id
event_abstract_obj.event_person_id = event_person_id
else:
return False
log.debug(type(event_abstract_obj))
log.debug(event_abstract_obj
)
event_abstract_dict = event_abstract_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'event_file_list', 'event_person', 'event_person_list', 'event_presenter_list', 'created_on', 'updated_on'})
if event_abstract_id:
if event_abstract_dict_up_result := sql_update(data=event_abstract_dict, table_name='event_abstract', rm_id_random=True):
log.info(f'Event Abstract updated. event_abstract_id={event_abstract_id}')
pass
else:
log.warning(f'Event Abstract not updated. event_abstract_id={event_abstract_id}')
log.debug(event_abstract_dict_up_result)
return False
log.debug(event_abstract_dict_up_result)
else:
if event_abstract_dict_in_result := sql_insert(data=event_abstract_dict, table_name='event_abstract', rm_id_random=True, id_random_length=None):
log.info(f'Event Abstract created. event_abstract_id={event_abstract_dict_in_result}')
else:
log.warning(f'Event Abstract not created.')
log.debug(event_abstract_dict_in_result)
return False
log.debug(event_abstract_dict_in_result)
event_abstract_id = event_abstract_dict_in_result # False, None, integer
event_abstract_outline = {}
event_abstract_outline['event_id'] = event_id
event_abstract_outline['event_abstract_id'] = event_abstract_id
event_abstract_outline['event_person_id'] = event_person_id
# event_abstract_outline['event_file_count'] = event_file_count
if return_outline:
log.debug(f'Returning the Event Abstract Outline: {event_abstract_outline}')
return event_abstract_outline
else:
log.debug(f'Returning the Event Abstract ID: {event_abstract_id}')
return event_abstract_id
# ### END ### API Event Abstract Methods ### create_update_event_abstract_obj() ###
# ### BEGIN ### API Event Abstract Methods ### create_update_event_abstract_obj_old() ###
# Updated 2023-03-20
@logger_reset
def create_update_event_abstract_obj_old(
event_abstract_dict_obj: Event_Abstract_In|dict,
event_abstract_id: int|str = None,
event_id: int|str = None,
event_person_id: int|str = None,
@@ -286,7 +356,7 @@ def create_update_event_abstract_obj(
if event_person_id:
event_abstract_dict['event_person_id'] = event_person_id
try:
event_abstract_obj = Event_Abstract_Base(**event_abstract_dict)
event_abstract_obj = Event_Abstract_In(**event_abstract_dict)
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_abstract_obj)
except ValidationError as e:
@@ -360,4 +430,63 @@ def create_update_event_abstract_obj(
else:
log.debug(f'Returning the Event Abstract ID: {event_abstract_id}')
return event_abstract_id
# ### END ### API Event Abstract Methods ### create_update_event_abstract_obj() ###
# ### END ### API Event Abstract Methods ### create_update_event_abstract_obj_old() ###
# ### BEGIN ### API Event Abstract Methods ### remove_event_abstract_obj() ###
# Updated 2023-03-22
@logger_reset
def remove_event_abstract_obj(
event_abstract_id: int,
method: None|str = None,
log_lvl: int = logging.DEBUG, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
) -> bool|None:
log.setLevel(log_lvl)
if method is None or method == 'disable':
data = {'enable': False}
if event_abstract_dict_up_result := sql_update(
table_name = 'event_abstract',
record_id = event_abstract_id,
data = data,
log_lvl = log_lvl,
):
log.info(f'Event Abstract was disabled.')
return True
else:
log.warning(f'Event Abstract not disabled.')
return event_abstract_dict_up_result # False or None
elif method == 'delete':
if event_abstract_dict_del_result := sql_delete(
table_name = 'event_abstract',
record_id = event_abstract_id,
log_lvl = log_lvl,
):
log.info(f'Event Abstract was deleted.')
return True
else:
log.warning(f'Event Abstract not deleted.')
return event_abstract_dict_del_result # False or None
elif method == 'hide':
data = {'hide': True}
if event_abstract_dict_up_result := sql_update(
table_name = 'event_abstract',
record_id = event_abstract_id,
data = data,
log_lvl = log_lvl,
):
log.info(f'Event Abstract was hidden.')
return True
else:
log.warning(f'Event Abstract not hidden.')
return event_abstract_dict_up_result # False or None
else:
log.error('We should not be here. Something went wrong in remove_event_abstract_obj()!')
return False
# ### END ### API Event Abstract Methods ### remove_event_abstract_obj() ###