from __future__ import annotations 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.lib_general import log, logging from app.methods.event_methods import load_event_obj # ### BEGIN ### API Event Methods ### load_event_obj_list() ### def load_event_obj_list( account_id: int|str, limit: int = 1000, model_as_dict: bool = False, enabled: str = 'enabled', # enabled, disabled, all inc_contact_1: bool = False, inc_contact_2: bool = False, inc_contact_3: bool = False, inc_event_abstract_list: bool = False, inc_event_badge_list: bool = False, inc_event_cfg: bool = False, inc_event_device_list: bool = False, inc_event_exhibit_list: bool = False, inc_event_file_list: bool = False, inc_event_location: bool = False, # For event_session child object inc_event_location_list: bool = False, inc_event_person_list: bool = False, inc_event_presentation_list: bool = False, inc_event_presenter_cat: bool = False, # For event_session child object inc_event_presenter_list: bool = False, inc_event_registration_cfg: bool = False, inc_event_registration_list: bool = False, inc_event_session_list: bool = False, inc_event_track: bool = False, # For event_session child object inc_event_track_list: bool = False, inc_location_address: bool = False, inc_poc_event_person: bool = False, inc_person: bool = False, inc_user: bool = False, ) -> list|bool: log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass else: return False data = {} data['account_id'] = account_id if enabled in ['enabled', 'disabled', 'all']: if enabled == 'enabled': data['enable'] = True sql_enabled = f'AND `tbl`.enable = :enable' elif enabled == 'disabled': data['enable'] = False sql_enabled = f'AND `tbl`.enable = :enable' elif enabled == 'all': sql_enabled = '' # else: tbl_obj['account'] = None if limit: data['limit'] = limit sql_limit = f'LIMIT :limit' else: sql_limit = '' sql = f""" SELECT `tbl`.id AS 'event_id', `tbl`.id_random AS 'event_id_random' FROM `event` AS `tbl` WHERE `tbl`.account_id = :account_id {sql_enabled} ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC {sql_limit}; """ if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True): log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(event_rec_li_result) event_result_li = [] for event_rec in event_rec_li_result: event_id = event_rec.get('event_id', None) if event_result := load_event_obj( event_id = event_id, limit = limit, model_as_dict = model_as_dict, enabled = enabled, # inc_location_address = inc_address, # inc_contact_1 = inc_contact, # inc_contact_2 = inc_contact, # inc_contact_3 = inc_contact, # inc_event_abstract_list = inc_event_abstract_list, # inc_event_badge_list = inc_event_badge_list, # inc_event_device_list = inc_event_device_list, inc_event_exhibit_list = inc_event_exhibit_list, inc_event_file_list = inc_event_file_list, inc_event_location_list = inc_event_location_list, inc_event_person_list = inc_event_person_list, inc_event_presentation_list = inc_event_presentation_list, inc_event_presenter_list = inc_event_presenter_list, inc_event_registration_list = inc_event_registration_list, inc_event_session_list = inc_event_session_list, inc_event_track_list = inc_event_track_list, # inc_person = inc_person, # inc_user = inc_user, ): log.debug(event_result) event_result_li.append(event_result) else: log.debug(event_result) event_result_li.append(None) log.debug(event_result_li) else: log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(event_rec_li_result) event_result_li = [] log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL return event_result_li # ### END ### API Event Methods ### load_event_obj_list() ###