Working on all module routes, methods, and models
This commit is contained in:
@@ -14,6 +14,7 @@ from app.methods.contact_methods import get_contact_rec_list, load_contact_obj
|
||||
from app.methods.event_methods import get_event_rec_list, load_event_obj
|
||||
from app.methods.hosted_file_methods import get_hosted_file_rec_list, load_hosted_file_obj
|
||||
from app.methods.journal_methods import get_journal_rec_list, load_journal_obj
|
||||
from app.methods.membership_cfg_methods import load_membership_cfg_obj
|
||||
from app.methods.membership_group_methods import get_membership_group_rec_list, load_membership_group_obj
|
||||
from app.methods.membership_member_methods import get_membership_member_rec_list, load_membership_member_obj
|
||||
from app.methods.membership_type_methods import get_membership_type_rec_list, load_membership_type_obj
|
||||
@@ -568,3 +569,269 @@ def load_account_obj(
|
||||
else:
|
||||
return account_obj
|
||||
# ### END ### API Account Methods ### load_account_obj() ###
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_obj_membership_type() ###
|
||||
# Working well as of 2021-06-11. Using as a template for other load objects.
|
||||
def load_account_obj_membership_type(
|
||||
account_id: int|str,
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
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_contact: bool = False,
|
||||
inc_membership_cfg: bool = False,
|
||||
inc_membership_group_list: bool = False, # List of groups for the account
|
||||
inc_membership_group_member_list: bool = False, # List of members of a group
|
||||
inc_membership_member: bool = False,
|
||||
inc_membership_member_list: bool = False, # Priority l1
|
||||
inc_membership_member_profile: bool = False,
|
||||
inc_membership_type: bool = False,
|
||||
inc_membership_type_list: bool = False,
|
||||
inc_order: bool = False,
|
||||
inc_order_cfg: bool = False,
|
||||
inc_order_list: bool = False, # Priority l1
|
||||
inc_order_line_list: bool = False, # Priority l2
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_product: bool = False,
|
||||
inc_product_list: bool = False, # Priority l3
|
||||
inc_user: bool = False,
|
||||
inc_user_list: bool = False, # Priority l2
|
||||
) -> Account_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_rec := sql_select(table_name='v_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_membership_cfg = inc_membership_cfg,
|
||||
):
|
||||
account_obj.account_cfg = account_cfg_dict
|
||||
else: account_obj.account_cfg = None
|
||||
|
||||
if inc_membership_cfg:
|
||||
if membership_cfg_dict := load_membership_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = model_as_dict,
|
||||
):
|
||||
account_obj.membership_cfg = membership_cfg_dict
|
||||
else: account_obj.membership_cfg = None
|
||||
|
||||
# Updated 2021-06-18
|
||||
if membership_type_rec_list_result := get_membership_type_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
membership_type_result_list = []
|
||||
for membership_type_rec in membership_type_rec_list_result:
|
||||
membership_type_result_list.append(
|
||||
load_membership_type_obj(
|
||||
membership_type_id = membership_type_rec.get('membership_type_id', None),
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_membership_group_list = inc_membership_group_list, # per member
|
||||
inc_membership_member_list = inc_membership_member_list,
|
||||
inc_membership_member_profile = inc_membership_member_profile,
|
||||
inc_product_list = inc_product_list,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
)
|
||||
)
|
||||
account_obj.membership_type_list = membership_type_result_list
|
||||
else: account_obj.membership_type_list = []
|
||||
|
||||
if model_as_dict:
|
||||
return account_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||
else:
|
||||
return account_obj
|
||||
# ### END ### API Account Methods ### load_account_obj_membership_type() ###
|
||||
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Account Methods ### load_account_obj_membership_group() ###
|
||||
# Working well as of 2021-06-11. Using as a template for other load objects.
|
||||
def load_account_obj_membership_group(
|
||||
account_id: int|str,
|
||||
limit: int = 1000,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
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_contact: bool = False,
|
||||
inc_membership_cfg: bool = False,
|
||||
# inc_membership_group_list: bool = False, # List of groups for the account
|
||||
inc_membership_group_member_list: bool = False, # List of members of a group
|
||||
inc_membership_member: bool = False,
|
||||
# inc_membership_member_list: bool = False, # Priority l1
|
||||
inc_membership_member_profile: bool = False,
|
||||
inc_membership_type: bool = False,
|
||||
# inc_membership_type_list: bool = False,
|
||||
# inc_order: bool = False,
|
||||
# inc_order_cfg: bool = False,
|
||||
# inc_order_list: bool = False, # Priority l1
|
||||
# inc_order_line_list: bool = False, # Priority l2
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
inc_product: bool = False,
|
||||
inc_product_list: bool = False, # Priority l3
|
||||
inc_user: bool = False,
|
||||
) -> Account_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_rec := sql_select(table_name='v_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_membership_cfg = inc_membership_cfg,
|
||||
):
|
||||
account_obj.account_cfg = account_cfg_dict
|
||||
else: account_obj.account_cfg = None
|
||||
|
||||
if inc_membership_cfg:
|
||||
if membership_cfg_dict := load_membership_cfg_obj(
|
||||
account_id = account_id,
|
||||
model_as_dict = model_as_dict,
|
||||
):
|
||||
account_obj.membership_cfg = membership_cfg_dict
|
||||
else: account_obj.membership_cfg = None
|
||||
|
||||
# Updated 2021-06-21
|
||||
if inc_membership_group_list:
|
||||
if membership_group_rec_list_result := get_membership_group_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
membership_group_result_list = []
|
||||
for membership_group_rec in membership_group_rec_list_result:
|
||||
membership_group_result_list.append(
|
||||
load_membership_group_obj(
|
||||
membership_group_id = membership_group_rec.get('membership_group_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
# inc_membership_member_list = inc_membership_member_list,
|
||||
inc_membership_group_member_list = inc_membership_group_member_list,
|
||||
inc_product_list = inc_product_list,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
)
|
||||
)
|
||||
account_obj.membership_group_list = membership_group_result_list
|
||||
else: account_obj.membership_group_list = []
|
||||
|
||||
# Updated 2021-06-21
|
||||
if inc_membership_member_list:
|
||||
if membership_member_rec_list_result := get_membership_member_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
membership_member_result_list = []
|
||||
for membership_member_rec in membership_member_rec_list_result:
|
||||
membership_member_result_list.append(
|
||||
load_membership_member_obj(
|
||||
membership_member_id = membership_member_rec.get('membership_member_id', None),
|
||||
limit = limit,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_membership_group_list = inc_membership_group_list,
|
||||
inc_membership_member_profile = inc_membership_member_profile,
|
||||
inc_membership_type = inc_membership_type,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
)
|
||||
)
|
||||
account_obj.membership_member_list = membership_member_result_list
|
||||
else: account_obj.membership_member_list = []
|
||||
|
||||
# Updated 2021-06-18
|
||||
if inc_membership_type_list:
|
||||
if membership_type_rec_list_result := get_membership_type_rec_list(
|
||||
for_obj_type = 'account',
|
||||
for_obj_id = account_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
membership_type_result_list = []
|
||||
for membership_type_rec in membership_type_rec_list_result:
|
||||
membership_type_result_list.append(
|
||||
load_membership_type_obj(
|
||||
membership_type_id = membership_type_rec.get('membership_type_id', None),
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
by_alias = by_alias,
|
||||
exclude_unset = exclude_unset,
|
||||
model_as_dict = model_as_dict,
|
||||
inc_address = inc_address,
|
||||
inc_contact = inc_contact,
|
||||
inc_membership_member_list = inc_membership_member_list,
|
||||
# inc_membership_type_member_list = inc_membership_type_member_list,
|
||||
inc_product_list = inc_product_list,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
)
|
||||
)
|
||||
account_obj.membership_type_list = membership_type_result_list
|
||||
else: account_obj.membership_type_list = []
|
||||
|
||||
if model_as_dict:
|
||||
return account_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
||||
else:
|
||||
return account_obj
|
||||
# ### END ### API Account Methods ### load_account_obj_membership_group() ###
|
||||
|
||||
Reference in New Issue
Block a user