Moving stuff around to make it more easy to manage. Adding models, methods, and routes.
This commit is contained in:
@@ -8,6 +8,7 @@ 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.archive_methods import load_archive_obj, load_archive_obj_list
|
||||
from app.methods.event_methods import load_event_obj
|
||||
|
||||
from app.models.account_models import Account_Base
|
||||
@@ -16,15 +17,19 @@ from app.models.account_cfg_models import Account_Cfg_Base
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_obj() ###
|
||||
# Working well as of 2021-06-11. Using as a template for other load objects.
|
||||
def load_account_obj(
|
||||
account_id: int|str,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
limit: int = 1000,
|
||||
model_as_dict: bool = False,
|
||||
enabled: str = 'enabled', # enabled, disabled, all
|
||||
inc_account_cfg: bool = False, # Priority l1
|
||||
inc_address: bool = False, # Under contact
|
||||
inc_address_list: bool = False, # Priority l3
|
||||
inc_archive: bool = False,
|
||||
inc_archive_list: bool = False, # Priority l1
|
||||
inc_archive_content: bool = False,
|
||||
inc_archive_content_list: bool = False, # Priority l2
|
||||
inc_contact: bool = False,
|
||||
inc_contact_list: bool = False, # Priority l3
|
||||
inc_event: bool = False,
|
||||
@@ -80,7 +85,7 @@ def load_account_obj(
|
||||
inc_site_list: bool = False, # Priority l3
|
||||
inc_user: bool = False,
|
||||
inc_user_list: bool = False, # Priority l2
|
||||
) -> Account_Base|bool:
|
||||
) -> Account_Base|dict|bool:
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -100,13 +105,28 @@ def load_account_obj(
|
||||
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)
|
||||
if account_cfg_dict := load_account_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = True,
|
||||
# inc_event_cfg = inc_event_cfg,
|
||||
inc_fundraising_cfg = inc_fundraising_cfg,
|
||||
inc_membership_cfg = inc_membership_cfg,
|
||||
):
|
||||
account_obj.account_cfg = account_cfg_dict
|
||||
else: account_obj.account_cfg = None
|
||||
|
||||
if inc_archive_list:
|
||||
if archive_dict_list := load_archive_obj_list(
|
||||
account_id = account_id,
|
||||
limit = limit,
|
||||
model_as_dict = True,
|
||||
enabled = enabled,
|
||||
inc_archive_content_list = inc_archive_content_list
|
||||
):
|
||||
account_obj.archive_list = archive_dict_list
|
||||
else: account_obj.archive_list = None
|
||||
|
||||
|
||||
# if inc_contact:
|
||||
# contact_id = account_rec.get('contact_id', None)
|
||||
# if contact_obj_result := load_contact_obj(contact_id=contact_id):
|
||||
@@ -206,5 +226,8 @@ def load_account_obj(
|
||||
account_obj.event_list = []
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
|
||||
return account_obj
|
||||
if model_as_dict:
|
||||
return account_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
|
||||
else:
|
||||
return account_obj
|
||||
# ### END ### API Account Methods ### load_account_obj() ###
|
||||
|
||||
Reference in New Issue
Block a user