Moving stuff around to make it more easy to manage

This commit is contained in:
Scott Idem
2021-06-11 10:55:08 -04:00
parent 60928b0521
commit 9c679765e5
7 changed files with 228 additions and 149 deletions

View File

@@ -0,0 +1,71 @@
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.event_methods import load_event_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:
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
else: return False
# ### END ### API Account Methods ### load_account_cfg_obj() ###
# ### 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 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() ###

View File

@@ -7,11 +7,12 @@ 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.account_cfg_methods import load_account_cfg_obj
from app.methods.event_methods import load_event_obj
from app.models.account_models import Account_Base
from app.models.account_cfg_models import Account_Cfg_Base
from app.models.membership_models import Membership_Cfg_Base
# from app.models.membership_cfg_models import Membership_Cfg_Base
# ### BEGIN ### API Account Methods ### load_account_obj() ###
@@ -19,22 +20,22 @@ def load_account_obj(
account_id: int|str,
enabled: str = 'enabled', # enabled, disabled, all
limit: int = 1000,
inc_account_cfg: bool = False,
inc_account_cfg: bool = False, # Priority l1
inc_address: bool = False, # Under contact
inc_address_list: bool = False,
inc_address_list: bool = False, # Priority l3
inc_archive: bool = False,
inc_archive_list: bool = False,
inc_archive_list: bool = False, # Priority l1
inc_contact: bool = False,
inc_contact_list: bool = False,
inc_contact_list: bool = False, # Priority l3
inc_event: bool = False,
inc_event_list: bool = False,
inc_event_abstract: bool = False,
inc_event_abstract_list: bool = False,
inc_event_badge: bool = False,
inc_event_badge_list: bool = False,
inc_event_list: bool = False, # Priority l1
# inc_event_abstract: bool = False,
# inc_event_abstract_list: bool = False,
# inc_event_badge: bool = False,
# inc_event_badge_list: bool = False,
inc_event_cfg: bool = False,
inc_event_device: bool = False,
inc_event_device_list: bool = False,
# inc_event_device: bool = False,
# inc_event_device_list: bool = False,
inc_event_exhibit: bool = False,
inc_event_exhibit_list: bool = False,
inc_event_file: bool = False,
@@ -53,29 +54,32 @@ def load_account_obj(
inc_event_registration_list: bool = False,
inc_event_session: bool = False,
inc_event_session_list: bool = False,
inc_event_track: bool = False, # For event_session child object
# inc_event_track: bool = False, # For event_session child object
inc_event_track_list: bool = False,
inc_fundraising_cfg: bool = False,
inc_hosted_file_list: bool = False,
inc_journal_list: bool = False,
inc_membership: bool = False,
inc_journal_list: bool = False, # Priority l3
# inc_membership: bool = False,
inc_membership_cfg: bool = False,
inc_membership_list: bool = False,
inc_order: bool = False,
inc_order_list: bool = False,
inc_order_list: bool = False, # Priority l2
inc_order_cart: bool = False,
inc_order_cart_list: bool = False,
inc_organization: bool = False,
inc_organization_list: bool = False,
inc_organization_list: bool = False, # Priority l3
# inc_page: bool = False,
inc_page_list: bool = False, # Priority l3
inc_person: bool = False,
inc_person_list: bool = False,
inc_person_list: bool = False, # Priority l2
inc_post: bool = False,
inc_post_list: bool = False,
inc_post_list: bool = False, # Priority l1
inc_product: bool = False,
inc_product_list: bool = False,
inc_site: bool = False,
inc_site_list: bool = False,
inc_product_list: bool = False, # Priority l3
# inc_site: bool = False,
inc_site_list: bool = False, # Priority l3
inc_user: bool = False,
inc_user_list: bool = False,
inc_user_list: bool = False, # Priority l2
) -> Account_Base|bool:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -95,6 +99,14 @@ def load_account_obj(
except ValidationError as e:
log.error(e.json())
if inc_account_cfg:
organization_id = account_rec.get('organization_id', None)
if account_cfg_obj_result := load_account_cfg_obj(account_id=account_id):
account_cfg_obj = account_cfg_obj_result
account_cfg_dict = account_cfg_obj.dict(by_alias=True, exclude_unset=True)
account_obj.account_cfg = account_cfg_dict
else: account_obj.account_cfg = None
# if inc_contact:
# contact_id = account_rec.get('contact_id', None)
# if contact_obj_result := load_contact_obj(contact_id=contact_id):
@@ -165,13 +177,13 @@ def load_account_obj(
if event_obj := load_event_obj(
event_id=event_id,
enabled=enabled,
inc_location_address=inc_address,
inc_contact_1=inc_contact,
inc_contact_2=inc_contact,
inc_contact_3=inc_contact,
inc_event_abstract_list=inc_event_abstract_list,
inc_event_badge_list=inc_event_badge_list,
inc_event_device_list=inc_event_device_list,
# inc_location_address=inc_address,
# inc_contact_1=inc_contact,
# inc_contact_2=inc_contact,
# inc_contact_3=inc_contact,
# inc_event_abstract_list=inc_event_abstract_list,
# inc_event_badge_list=inc_event_badge_list,
# inc_event_device_list=inc_event_device_list,
inc_event_exhibit_list=inc_event_exhibit_list,
inc_event_file_list=inc_event_file_list,
inc_event_location_list=inc_event_location_list,
@@ -181,8 +193,8 @@ def load_account_obj(
inc_event_registration_list=inc_event_registration_list,
inc_event_session_list=inc_event_session_list,
inc_event_track_list=inc_event_track_list,
inc_person=inc_person,
inc_user=inc_user
# inc_person=inc_person,
# inc_user=inc_user
):
data = event_obj.dict(by_alias=True, exclude_unset=True)
event_obj_li.append(data)
@@ -196,27 +208,3 @@ def load_account_obj(
return account_obj
# ### END ### API Account Methods ### load_account_obj() ###
# ### 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 account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
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() ###