104 lines
4.6 KiB
Python
104 lines
4.6 KiB
Python
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.address_methods import load_address_obj
|
|
# from app.methods.contact_methods import load_contact_obj
|
|
from app.methods.event_person_methods import get_event_person_rec_list, load_event_person_obj
|
|
from app.methods.event_registration_cfg_methods import load_event_registration_cfg_obj
|
|
# from app.methods.person_methods import load_person_obj
|
|
|
|
from app.models.event_registration_models import Event_Registration_Base
|
|
from app.models.event_cfg_models import Event_Cfg_Base
|
|
|
|
|
|
# ### BEGIN ### API Event Registration Methods ### load_event_registration_obj() ###
|
|
def load_event_registration_obj(
|
|
event_registration_id: int|str,
|
|
limit: int = 1000,
|
|
by_alias: bool = True,
|
|
exclude_unset: bool = True,
|
|
model_as_dict: bool = False,
|
|
enabled: str = 'enabled', # enabled, disabled, all
|
|
inc_address: bool = False, # Under contact
|
|
inc_contact: bool = False,
|
|
# inc_event_cfg: bool = False,
|
|
inc_event_person_list: bool = False,
|
|
inc_event_registration_cfg: bool = False,
|
|
# inc_event_registration_list: bool = False,
|
|
inc_person: bool = False,
|
|
) -> Event_Registration_Base|bool:
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if event_registration_id := redis_lookup_id_random(record_id_random=event_registration_id, table_name='event_registration'): pass
|
|
else: return False
|
|
|
|
if event_registration_rec := sql_select(table_name='v_event_registration', record_id=event_registration_id): pass
|
|
else: return False
|
|
|
|
print('******************************** HERE')
|
|
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(event_registration_rec)
|
|
|
|
try:
|
|
log.info('Try to apply event registration record data to Event_Registration_Base...')
|
|
event_registration_obj = Event_Registration_Base(**event_registration_rec)
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(event_registration_obj)
|
|
except ValidationError as e:
|
|
log.error(e.json())
|
|
return False
|
|
|
|
# Updated 2021-08-17
|
|
if inc_event_registration_cfg:
|
|
log.info('Need to include event registration configuration...')
|
|
event_id = event_registration_rec.get('event_id', None)
|
|
log.info(f'Need to include event registration config for event_id {event_id}...')
|
|
if event_registration_cfg_result := load_event_registration_cfg_obj(
|
|
event_id = event_id,
|
|
by_alias = by_alias,
|
|
exclude_unset = exclude_unset,
|
|
model_as_dict = model_as_dict,
|
|
):
|
|
event_registration_obj.cfg = event_registration_cfg_result
|
|
else: event_registration_obj.event_registration_cfg = None
|
|
|
|
# Updated 2021-08-17
|
|
if inc_event_person_list:
|
|
log.info('Need to include event person list...')
|
|
if event_person_rec_list_result := get_event_person_rec_list(
|
|
for_obj_type = 'event_registration',
|
|
for_obj_id = event_registration_id,
|
|
limit = limit,
|
|
enabled = enabled,
|
|
):
|
|
event_person_result_list = []
|
|
for event_person_rec in event_person_rec_list_result:
|
|
if load_event_person_result := load_event_person_obj(
|
|
event_person_id = event_person_rec.get('event_person_id', None),
|
|
limit = limit,
|
|
by_alias = by_alias,
|
|
exclude_unset = exclude_unset,
|
|
model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
inc_person = inc_person,
|
|
# inc_user = inc_user,
|
|
):
|
|
event_person_result_list.append(load_event_person_result)
|
|
else: event_person_result_list.append(None)
|
|
event_registration_obj.event_person_list = event_person_result_list
|
|
else: event_registration_obj.event_person_list = []
|
|
|
|
if model_as_dict:
|
|
return event_registration_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
|
else:
|
|
return event_registration_obj
|
|
# ### END ### API Event Registration Methods ### load_event_registration_obj() ###
|