45 lines
1.4 KiB
Python
45 lines
1.4 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.models.order_cfg_models import Order_Cfg_Base
|
|
|
|
|
|
# ### BEGIN ### API Order Cfg Methods ### load_order_cfg_obj() ###
|
|
def load_order_cfg_obj(
|
|
account_id: int|str,
|
|
by_alias: bool = True,
|
|
exclude_unset: bool = True,
|
|
model_as_dict: bool = False,
|
|
) -> Order_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 order_cfg_rec := sql_select(
|
|
table_name = 'v_account_cfg_detail',
|
|
field_name = 'account_id',
|
|
field_value = account_id,
|
|
): pass
|
|
else: return False
|
|
log.debug(order_cfg_rec)
|
|
|
|
try:
|
|
order_cfg_obj = Order_Cfg_Base(**order_cfg_rec)
|
|
log.debug(order_cfg_obj)
|
|
except ValidationError as e:
|
|
log.error(e.json())
|
|
|
|
if model_as_dict:
|
|
return order_cfg_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
|
else:
|
|
return order_cfg_obj
|
|
# ### END ### API Order Cfg Methods ### load_order_cfg_obj() ###
|