Files
OSIT-AE-API-FastAPI/app/methods/account_cfg_methods.py

63 lines
2.2 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_select
from app.lib_general import log, logging
from app.methods.membership_cfg_methods import load_membership_cfg_obj
from app.models.account_cfg_models import Account_Cfg_Base
# ### BEGIN ### API Account Cfg Methods ### load_account_cfg_obj() ###
def load_account_cfg_obj(
account_id: int|str,
model_as_dict: bool = False,
# inc_event_cfg: bool = False,
inc_fundraising_cfg: bool = False,
inc_membership_cfg: bool = False,
) -> Account_Cfg_Base|dict|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
if account_cfg_rec := sql_select(
table_name = 'v_account_cfg_detail', # This view should probably be cleaned up
field_name = 'account_id',
field_value = account_id
): pass
else: return False
log.debug(account_cfg_rec)
try:
account_cfg_obj = Account_Cfg_Base(**account_cfg_rec)
log.debug(account_cfg_obj)
except ValidationError as e:
log.error(e.json())
if inc_fundraising_cfg:
if fundraising_cfg_dict := load_fundraising_cfg_obj(
account_id = account_id,
model_as_dict = model_as_dict,
):
account_cfg_obj.fundraising_cfg = fundraising_cfg_dict
else: account_cfg_obj.fundraising_cfg = None
if inc_membership_cfg:
if membership_cfg_dict := load_membership_cfg_obj(
account_id = account_id,
model_as_dict = model_as_dict,
):
account_cfg_obj.membership_cfg = membership_cfg_dict
else: account_cfg_obj.membership_cfg = None
if model_as_dict:
return account_cfg_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
else:
return account_cfg_obj
# ### END ### API Account Cfg Methods ### load_account_cfg_obj() ###