Working on membership, fundraising, and products

This commit is contained in:
Scott Idem
2021-07-01 14:02:24 -04:00
parent 59c151f639
commit 3631f2f122
5 changed files with 143 additions and 117 deletions

View File

@@ -13,7 +13,7 @@ from app.models.product_models import Product_Base
# ### BEGIN ### API Product Methods ### load_product_obj() ###
def load_product_obj(
product_id: int|str,
limit: int = 1000,
# limit: int = 1000,
by_alias: bool = True,
exclude_unset: bool = True,
model_as_dict: bool = False,
@@ -41,79 +41,73 @@ def load_product_obj(
# ### BEGIN ### API Product Methods ### get_product_rec_list() ###
# Updated 2021-06-23
# Updated 2021-07-01
def get_product_rec_list(
for_obj_type: str,
for_obj_id: str,
account_id: str = None,
for_obj_type: str = None,
for_obj_id: str = None,
prod_type: str = None,
limit: int = 1000,
enabled: str = 'enabled', # enabled, disabled, all
) -> list|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name='for_obj_type'): pass
else: return False
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
if for_obj_id := redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type): pass
data = {}
if for_obj_type == 'account':
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_id'
data['account_id'] = account_id
data['for_obj_type'] = for_obj_type
data['for_obj_id'] = for_obj_id
if enabled in ['enabled', 'disabled', 'all']:
if enabled == 'enabled':
data['enable'] = True
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'disabled':
data['enable'] = False
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
if account_id:
sql_account_id = f'`product`.account_id = :account_id'
else: sql_account_id = ''
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
if for_obj_type and for_obj_id: # event_exhibit, event_registration, fundraising, membership_group, membership_type
if for_obj_type == 'account':
sql_account_id = f'`product`.account_id = :for_obj_id'
sql_for_obj_type_id = ''
else:
sql_limit = ''
sql_for_obj_type_id = f'`product`.for_type = :for_obj_type AND `product`.for_id = :for_obj_id'
else: sql_for_obj_type_id = ''
sql = f"""
SELECT `tbl`.id AS 'product_id', `tbl`.id_random AS 'product_id_random'
FROM `product` AS `tbl`
WHERE
{sql_obj_type_id}
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
else: # event_exhibit, event_registration, fundraising, membership_group, membership_type
data['for_obj_type'] = for_obj_type
data['for_obj_id'] = for_obj_id
if enabled in ['enabled', 'disabled', 'all']:
if enabled == 'enabled':
data['enable'] = True
sql_enabled = f'AND `product`.enable = :enable'
elif enabled == 'disabled':
data['enable'] = False
sql_enabled = f'AND `product`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
else: sql_enabled = ''
sql_obj_type_id = f'`tbl`.for_type = :for_obj_type AND `tbl`.for_id = :for_obj_id'
if prod_type in ['event', 'event_option', 'event_registration', 'fundraising', 'membership_group', 'membership_type']:
data['type_name'] = prod_type
if enabled in ['enabled', 'disabled', 'all']:
if enabled == 'enabled':
data['enable'] = True
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'disabled':
data['enable'] = False
sql_enabled = f'AND `tbl`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
sql_product_type = f"""AND product.type_name = :type_name"""
else: sql_product_type = ''
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `product`.id AS 'product_id', `product`.id_random AS 'product_id_random'
FROM `v_product` AS `product`
WHERE
{sql_account_id}
{sql_for_obj_type_id}
{sql_product_type}
{sql_enabled}
ORDER BY `product`.created_on DESC, `product`.updated_on DESC
{sql_limit};
"""
sql = f"""
SELECT `tbl`.id AS 'product_id', `tbl`.id_random AS 'product_id_random'
FROM `product` AS `tbl`
WHERE
{sql_obj_type_id}
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(sql)