Moving stuff around to make it more easy to manage. Adding models, methods, and routes.
This commit is contained in:
@@ -7,65 +7,56 @@ from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, v
|
||||
from app.db_sql import redis_lookup_id_random, sql_select
|
||||
from app.lib_general import log, logging
|
||||
|
||||
from app.methods.event_methods import load_event_obj
|
||||
from app.methods.membership_cfg_methods import load_membership_cfg_obj
|
||||
|
||||
from app.models.account_cfg_models import Account_Cfg_Base
|
||||
# from app.models.membership_cfg_models import Membership_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_cfg_obj() ###
|
||||
def load_account_cfg_obj(account_id:int|str) -> Account_Cfg_Base|bool:
|
||||
# ### 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', field_name='account_id', field_value=account_id):
|
||||
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())
|
||||
|
||||
return account_cfg_obj
|
||||
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
|
||||
# ### END ### API Account Methods ### load_account_cfg_obj() ###
|
||||
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
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_cfg_obj() ###
|
||||
# def load_account_cfg_obj(account_id:int|str, inc_event_cfg:bool=False, inc_fundraising_cfg:bool=False, inc_membership_cfg:bool=False):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
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 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', field_name='account_id', field_value=account_id):
|
||||
# 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())
|
||||
|
||||
# return account_cfg_obj
|
||||
# else: return False
|
||||
|
||||
# if inc_membership_cfg:
|
||||
# if membership_cfg_rec := sql_select(table_name='v_membership_cfg', field_name='account_id', field_value=account_id):
|
||||
# #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(membership_cfg_rec)
|
||||
|
||||
# #account_rec['membership_cfg'] = membership_cfg_rec
|
||||
# try:
|
||||
# membership_cfg_obj = Membership_Cfg_Base(**membership_cfg_rec)
|
||||
# log.debug(membership_cfg_obj)
|
||||
# except ValidationError as e:
|
||||
# log.error(e.json())
|
||||
|
||||
# return membership_cfg_obj
|
||||
# ### END ### API Account Methods ### load_account_cfg_obj() ###
|
||||
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() ###
|
||||
|
||||
Reference in New Issue
Block a user