211 lines
8.6 KiB
Python
211 lines
8.6 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.account_cfg_methods import load_account_cfg_obj
|
|
# from app.methods.address_methods import load_address_obj_list
|
|
from app.methods.archive_methods import load_archive_obj_list
|
|
# from app.methods.contact_methods import load_contact_obj_list
|
|
from app.methods.event_methods import load_event_obj_list
|
|
from app.methods.post_methods import load_post_obj_list
|
|
|
|
from app.models.account_models import Account_Base
|
|
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_obj() ###
|
|
# Working well as of 2021-06-11. Using as a template for other load objects.
|
|
def load_account_obj(
|
|
account_id: int|str,
|
|
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,
|
|
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_exhibit: bool = False,
|
|
inc_event_exhibit_list: bool = False,
|
|
inc_event_file: bool = False,
|
|
inc_event_file_list: bool = False,
|
|
inc_event_location: bool = False, # For event_session child object
|
|
inc_event_location_list: bool = False,
|
|
inc_event_person: bool = False,
|
|
inc_event_person_list: bool = False,
|
|
inc_event_presentation: bool = False,
|
|
inc_event_presentation_list: bool = False,
|
|
inc_event_presenter_cat: bool = False, # For event_session child object
|
|
inc_event_presenter: bool = False,
|
|
inc_event_presenter_list: bool = False,
|
|
inc_event_registration: bool = False,
|
|
inc_event_registration_cfg: bool = False,
|
|
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_list: bool = False,
|
|
inc_fundraising_cfg: bool = False,
|
|
inc_hosted_file_list: 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, # Priority l2
|
|
inc_order_cart: bool = False,
|
|
inc_order_cart_list: bool = False,
|
|
inc_organization: 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, # Priority l2
|
|
inc_post: bool = False,
|
|
inc_post_list: bool = False, # Priority l1
|
|
inc_post_comment: bool = False,
|
|
inc_post_comment_list: bool = False,
|
|
inc_product: 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, # Priority l2
|
|
) -> Account_Base|dict|bool:
|
|
log.setLevel(logging.DEBUG) # 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_rec := sql_select(table_name='account', record_id=account_id): pass
|
|
else: return False
|
|
|
|
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(account_rec)
|
|
|
|
try:
|
|
account_obj = Account_Base(**account_rec)
|
|
log.debug(account_obj)
|
|
except ValidationError as e:
|
|
log.error(e.json())
|
|
|
|
if inc_account_cfg:
|
|
if account_cfg_dict := load_account_cfg_obj(
|
|
account_id = account_id,
|
|
model_as_dict = model_as_dict,
|
|
# 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_address_list:
|
|
if address_dict_list := load_address_obj_list(
|
|
account_id = account_id,
|
|
limit = limit,
|
|
model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
):
|
|
account_obj.address_list = address_dict_list
|
|
else: account_obj.address_list = []
|
|
|
|
if inc_archive_list:
|
|
if archive_dict_list := load_archive_obj_list(
|
|
account_id = account_id,
|
|
limit = limit,
|
|
model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
inc_archive_content_list = inc_archive_content_list,
|
|
):
|
|
account_obj.archive_list = archive_dict_list
|
|
else: account_obj.archive_list = []
|
|
|
|
if inc_contact_list:
|
|
if contact_dict_list := load_contact_obj_list(
|
|
account_id = account_id,
|
|
limit = limit,
|
|
model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
inc_address = inc_address,
|
|
):
|
|
account_obj.contact_list = contact_dict_list
|
|
else: account_obj.contact_list = []
|
|
|
|
# if inc_organization:
|
|
# organization_id = account_rec.get('organization_id', None)
|
|
# if organization_obj_result := load_organization_obj(organization_id=organization_id):
|
|
# organization_obj = organization_obj_result
|
|
# # account_rec['organization'] = organization_obj
|
|
# # log.debug(account_rec)
|
|
# #account_obj.organization = organization_obj.dict(by_alias=True, exclude_unset=True)
|
|
# account_obj.organization = organization_obj
|
|
# else: account_obj.organization = None
|
|
|
|
if inc_event_list:
|
|
if event_dict_list := load_event_obj_list(
|
|
account_id = account_id,
|
|
limit = limit,
|
|
model_as_dict = model_as_dict,
|
|
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_event_exhibit_list = inc_event_exhibit_list,
|
|
inc_event_file_list = inc_event_file_list,
|
|
inc_event_location_list = inc_event_location_list,
|
|
inc_event_person_list = inc_event_person_list,
|
|
inc_event_presentation_list = inc_event_presentation_list,
|
|
inc_event_presenter_list = inc_event_presenter_list,
|
|
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,
|
|
):
|
|
account_obj.event_list = event_dict_list
|
|
else: account_obj.event_list = []
|
|
|
|
if inc_post_list:
|
|
if post_dict_list := load_post_obj_list(
|
|
account_id = account_id,
|
|
limit = limit,
|
|
model_as_dict = model_as_dict,
|
|
enabled = enabled,
|
|
inc_post_comment_list = inc_post_comment_list,
|
|
inc_person = inc_person,
|
|
inc_user = inc_user,
|
|
):
|
|
account_obj.post_list = post_dict_list
|
|
else: account_obj.post_list = []
|
|
|
|
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() ###
|