59 lines
2.0 KiB
Python
59 lines
2.0 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.event_registration_cfg_methods import load_event_registration_cfg_obj
|
|
|
|
from app.models.event_cfg_models import Event_Cfg_Base
|
|
|
|
|
|
# ### BEGIN ### API Event Cfg Methods ### load_event_cfg_obj() ###
|
|
def load_event_cfg_obj(
|
|
event_id: int|str,
|
|
inc_event_registration_cfg: bool = False,
|
|
limit: int = 1000,
|
|
by_alias: bool = True,
|
|
exclude_unset: bool = True,
|
|
model_as_dict: bool = False,
|
|
) -> Event_Cfg_Base|bool:
|
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if event_id := redis_lookup_id_random(record_id_random=event_id, table_name='event'): pass
|
|
else: return False
|
|
|
|
if event_cfg_rec := sql_select(table_name='v_event_cfg', record_id=event_id): pass
|
|
else: return False
|
|
|
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(event_cfg_rec)
|
|
|
|
try:
|
|
event_cfg_obj = Event_Cfg_Base(**event_cfg_rec)
|
|
log.debug(event_cfg_obj)
|
|
except ValidationError as e:
|
|
log.error(e.json())
|
|
return False
|
|
|
|
# Updated 2021-06-30
|
|
if inc_event_registration_cfg:
|
|
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_cfg_obj.event_registration_cfg = event_registration_cfg_result
|
|
else: event_cfg_obj.event_registration_cfg = None
|
|
|
|
if model_as_dict:
|
|
return event_cfg_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
|
else:
|
|
return event_cfg_obj
|
|
# ### END ### API Event Cfg Methods ### load_event_cfg_obj() ###
|