Updates related to abstracts

This commit is contained in:
Scott Idem
2023-06-28 12:22:08 -04:00
parent dc974135bf
commit 815e9a45b4
6 changed files with 120 additions and 104 deletions

View File

@@ -11,6 +11,7 @@ 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_Ext, Event_Abstract_In
from app.methods.event_cfg_methods import load_event_cfg_obj
# ### BEGIN ### API Event Abstract Methods ### load_event_abstract_obj() ###
@@ -24,6 +25,7 @@ def load_event_abstract_obj(
hidden: str = 'not_hidden', # hidden, not_hidden, all
review: str = 'all', # ready, not_ready, all
inc_event_cfg: bool = False,
inc_event_file_list: bool = False,
inc_event_person: bool = False,
inc_event_person_profile: bool = False,
@@ -53,6 +55,19 @@ def load_event_abstract_obj(
log.error(e.json())
return False
# Updated 2023-06-28
if inc_event_cfg:
log.info('Need to include event configuration...')
if event_cfg_result := load_event_cfg_obj(
event_id = event_abstract_obj.event_id,
by_alias = by_alias,
exclude_unset = exclude_unset,
model_as_dict = model_as_dict,
):
event_abstract_obj.event_cfg = event_cfg_result
else: event_abstract_obj.event_cfg = {} # None
log.debug(event_abstract_obj.event_cfg)
# Updated 2023-03-20
if inc_event_file_list:
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL

View File

@@ -150,79 +150,69 @@ def get_grant_rec_list(
# ### END ### API Grant Methods ### get_grant_rec_list() ###
# # ### BEGIN ### API Grant Methods ### create_update_grant_obj() ###
# # Updated 2023-03-22
# @logger_reset
# def create_update_grant_obj(
# grant_obj: Grant_In,
# grant_id: int = None,
# event_id: int = None,
# event_person_id: int = None,
# ### BEGIN ### API Grant Methods ### create_update_grant_obj() ###
# Updated 2023-06-28
@logger_reset
def create_update_grant_obj(
grant_obj: Grant_In,
grant_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())
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 grant_id:
# log.info(f'Got: grant_id={grant_id}; Update existing Grant')
# grant_obj.id = grant_id
# elif event_id and event_person_id:
# log.info(f'Got: event_id={event_id}; event_person_id={event_person_id}; Create Grant')
# grant_obj.event_id = event_id
# grant_obj.event_person_id = event_person_id
# else:
# return False
log.info('Checking requirements...')
if grant_id:
log.info(f'Got: grant_id={grant_id}; Update existing Grant')
grant_obj.id = grant_id
elif event_id:
log.info(f'Got: event_id={event_id}; Create Grant')
grant_obj.event_id = event_id
else:
return False
# log.debug(type(grant_obj))
# log.debug(grant_obj
# )
log.debug(type(grant_obj))
log.debug(grant_obj
)
# grant_dict = grant_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'})
grant_dict = grant_obj.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'event_abstract', 'event_person', 'created_on', 'updated_on'})
# # log.debug(type(grant_dict.get('topics_json', None)))
# # if 'topics_json' in grant_dict and (isinstance(grant_dict['topics_json'], dict) or isinstance(grant_dict['topics_json'], list)):
# # log.debug('Need to convert to JSON string')
# # grant_dict['topics_json'] = json.dumps(grant_dict['topics_json'])
# # log.debug(grant_dict)
if grant_id:
if grant_dict_up_result := sql_update(data=grant_dict, table_name='grant', rm_id_random=True):
log.info(f'Grant updated. grant_id={grant_id}')
pass
else:
log.warning(f'Grant not updated. grant_id={grant_id}')
log.debug(grant_dict_up_result)
return False
log.debug(grant_dict_up_result)
else:
if grant_dict_in_result := sql_insert(data=grant_dict, table_name='grant', rm_id_random=True, id_random_length=None):
log.info(f'Grant created. grant_id={grant_dict_in_result}')
else:
log.warning(f'Grant not created.')
log.debug(grant_dict_in_result)
return False
log.debug(grant_dict_in_result)
grant_id = grant_dict_in_result # False, None, integer
# if grant_id:
# if grant_dict_up_result := sql_update(data=grant_dict, table_name='grant', rm_id_random=True):
# log.info(f'Grant updated. grant_id={grant_id}')
# pass
# else:
# log.warning(f'Grant not updated. grant_id={grant_id}')
# log.debug(grant_dict_up_result)
# return False
# log.debug(grant_dict_up_result)
# else:
# if grant_dict_in_result := sql_insert(data=grant_dict, table_name='grant', rm_id_random=True, id_random_length=None):
# log.info(f'Grant created. grant_id={grant_dict_in_result}')
# else:
# log.warning(f'Grant not created.')
# log.debug(grant_dict_in_result)
# return False
# log.debug(grant_dict_in_result)
grant_outline = {}
grant_outline['event_id'] = event_id
grant_outline['grant_id'] = grant_id
# grant_id = grant_dict_in_result # False, None, integer
# grant_outline = {}
# grant_outline['event_id'] = event_id
# grant_outline['grant_id'] = grant_id
# grant_outline['event_person_id'] = event_person_id
# # grant_outline['event_file_count'] = event_file_count
# if return_outline:
# log.debug(f'Returning the Grant Outline: {grant_outline}')
# return grant_outline
# else:
# log.debug(f'Returning the Grant ID: {grant_id}')
# return grant_id
# # ### END ### API Grant Methods ### create_update_grant_obj() ###
if return_outline:
log.debug(f'Returning the Grant Outline: {grant_outline}')
return grant_outline
else:
log.debug(f'Returning the Grant ID: {grant_id}')
return grant_id
# ### END ### API Grant Methods ### create_update_grant_obj() ###