Clean up and working on user related models, methods, and routes.

This commit is contained in:
Scott Idem
2021-06-11 15:00:39 -04:00
parent 03bb55e62a
commit 29dfcc5440
7 changed files with 476 additions and 139 deletions

View File

@@ -8,8 +8,9 @@ from app.db_sql import redis_lookup_id_random, sql_select
from app.lib_general import log, logging from app.lib_general import log, logging
from app.methods.account_cfg_methods import load_account_cfg_obj 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.archive_methods import load_archive_obj_list
from app.methods.event_methods import load_event_obj 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_models import Account_Base
from app.models.account_cfg_models import Account_Cfg_Base from app.models.account_cfg_models import Account_Cfg_Base
@@ -79,6 +80,8 @@ def load_account_obj(
inc_person_list: bool = False, # Priority l2 inc_person_list: bool = False, # Priority l2
inc_post: bool = False, inc_post: bool = False,
inc_post_list: bool = False, # Priority l1 inc_post_list: bool = False, # Priority l1
inc_post_comment: bool = False,
inc_post_comment_list: bool = False,
inc_product: bool = False, inc_product: bool = False,
inc_product_list: bool = False, # Priority l3 inc_product_list: bool = False, # Priority l3
# inc_site: bool = False, # inc_site: bool = False,
@@ -121,11 +124,10 @@ def load_account_obj(
limit = limit, limit = limit,
model_as_dict = True, model_as_dict = True,
enabled = enabled, enabled = enabled,
inc_archive_content_list = inc_archive_content_list inc_archive_content_list = inc_archive_content_list,
): ):
account_obj.archive_list = archive_dict_list account_obj.archive_list = archive_dict_list
else: account_obj.archive_list = None else: account_obj.archive_list = []
# if inc_contact: # if inc_contact:
# contact_id = account_rec.get('contact_id', None) # contact_id = account_rec.get('contact_id', None)
@@ -156,75 +158,45 @@ def load_account_obj(
# else: account_obj.organization = None # else: account_obj.organization = None
if inc_event_list: if inc_event_list:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL if event_dict_list := load_event_obj_list(
account_id = account_id,
limit = limit,
model_as_dict = True,
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 = []
data = {} if inc_post_list:
data['account_id'] = account_id if post_dict_list := load_post_obj_list(
account_id = account_id,
if enabled in ['enabled', 'disabled', 'all']: limit = limit,
if enabled == 'enabled': model_as_dict = True,
data['enable'] = True enabled = enabled,
sql_enabled = f'AND `event`.enable = :enable' inc_post_comment_list = inc_post_comment_list,
elif enabled == 'disabled': inc_person = inc_person,
data['enable'] = False inc_user = inc_user,
sql_enabled = f'AND `event`.enable = :enable' ):
elif enabled == 'all': account_obj.post_list = post_dict_list
sql_enabled = '' else: account_obj.post_list = []
# else: event_obj['account'] = None
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `event`.id AS 'event_id', `event`.id_random AS 'event_id_random'
FROM `event` AS `event`
WHERE `event`.account_id = :account_id
{sql_enabled}
ORDER BY `event`.created_on DESC, `event`.updated_on DESC
{sql_limit};
"""
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_rec_li_result)
event_obj_li = []
for event_rec in event_rec_li_result:
event_id = event_rec.get('event_id', None)
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_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
):
data = event_obj.dict(by_alias=True, exclude_unset=True)
event_obj_li.append(data)
log.debug(event_obj_li)
account_obj.event_list = event_obj_li
else:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_rec_li_result)
account_obj.event_list = []
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if model_as_dict: if model_as_dict:
return account_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member return account_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member

View File

@@ -41,9 +41,9 @@ def load_archive_obj(
if inc_archive_content_list: if inc_archive_content_list:
if archive_content_dict_list := load_archive_content_obj_list( if archive_content_dict_list := load_archive_content_obj_list(
archive_id = archive_id, archive_id = archive_id,
limit=limit, limit = limit,
model_as_dict = True, model_as_dict = True,
enabled=enabled, enabled = enabled,
# inc_archive_content_content_list=inc_archive_content_content_list # inc_archive_content_content_list=inc_archive_content_content_list
): ):
archive_obj.archive_content_list = archive_content_dict_list archive_obj.archive_content_list = archive_content_dict_list
@@ -106,10 +106,10 @@ def load_archive_obj_list(
for archive_rec in archive_rec_li_result: for archive_rec in archive_rec_li_result:
archive_id = archive_rec.get('archive_id', None) archive_id = archive_rec.get('archive_id', None)
if archive_result := load_archive_obj( if archive_result := load_archive_obj(
archive_id=archive_id, archive_id = archive_id,
model_as_dict=model_as_dict, model_as_dict = model_as_dict,
enabled=enabled, enabled = enabled,
inc_archive_content_list=inc_archive_content_list, inc_archive_content_list = inc_archive_content_list,
): ):
log.debug(archive_result) log.debug(archive_result)
archive_result_li.append(archive_result) archive_result_li.append(archive_result)

View File

@@ -17,8 +17,9 @@ from app.models.event_models import Event_Base, Event_Cfg_Base
# ### BEGIN ### API Event Methods ### load_event_obj() ### # ### BEGIN ### API Event Methods ### load_event_obj() ###
def load_event_obj( def load_event_obj(
event_id: int|str, event_id: int|str,
enabled: str = 'enabled', # enabled, disabled, all model_as_dict: bool = False,
limit: int = 1000, limit: int = 1000,
enabled: str = 'enabled', # enabled, disabled, all
inc_contact_1: bool = False, inc_contact_1: bool = False,
inc_contact_2: bool = False, inc_contact_2: bool = False,
inc_contact_3: bool = False, inc_contact_3: bool = False,
@@ -136,6 +137,7 @@ def load_event_obj(
event_session_id = event_session_obj.get('event_session_id', None) event_session_id = event_session_obj.get('event_session_id', None)
if event_session_obj := load_event_session_obj( if event_session_obj := load_event_session_obj(
event_session_id=event_session_id, event_session_id=event_session_id,
limit = limit,
enabled=enabled, enabled=enabled,
inc_event_abstract_list=inc_event_abstract_list, inc_event_abstract_list=inc_event_abstract_list,
inc_event_device_list=inc_event_device_list, inc_event_device_list=inc_event_device_list,
@@ -176,6 +178,7 @@ def load_event_obj(
# ### BEGIN ### API Event Methods ### load_event_cfg_obj() ### # ### BEGIN ### API Event Methods ### load_event_cfg_obj() ###
def load_event_cfg_obj( def load_event_cfg_obj(
event_id: int|str, event_id: int|str,
model_as_dict: bool = False,
) -> Event_Cfg_Base|bool: ) -> Event_Cfg_Base|bool:
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL #log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())
@@ -199,6 +202,118 @@ def load_event_cfg_obj(
# ### END ### API Event Methods ### load_event_cfg_obj() ### # ### END ### API Event Methods ### load_event_cfg_obj() ###
# ### BEGIN ### API Event Methods ### load_event_obj_list() ###
def load_event_obj_list(
account_id: int|str,
limit: int = 1000,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_contact_1: bool = False,
inc_contact_2: bool = False,
inc_contact_3: bool = False,
inc_event_abstract_list: bool = False,
inc_event_badge_list: bool = False,
inc_event_cfg: bool = False,
inc_event_device_list: bool = False,
inc_event_exhibit_list: 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_list: bool = False,
inc_event_presentation_list: bool = False,
inc_event_presenter_cat: bool = False, # For event_session child object
inc_event_presenter_list: bool = False,
inc_event_registration_cfg: bool = False,
inc_event_registration_list: 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_location_address: bool = False,
inc_poc_event_person: bool = False,
inc_person: bool = False,
inc_user: bool = False,
) -> list|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
data = {}
data['account_id'] = account_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 = ''
# else: tbl_obj['account'] = None
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `tbl`.id AS 'event_id', `tbl`.id_random AS 'event_id_random'
FROM `event` AS `tbl`
WHERE `tbl`.account_id = :account_id
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
if event_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_rec_li_result)
event_result_li = []
for event_rec in event_rec_li_result:
event_id = event_rec.get('event_id', None)
if event_result := load_event_obj(
event_id = event_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,
):
log.debug(event_result)
event_result_li.append(event_result)
else:
log.debug(event_result)
event_result_li.append(None)
log.debug(event_result_li)
else:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(event_rec_li_result)
event_result_li = []
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
return event_result_li
# ### END ### API Event Methods ### load_event_obj_list() ###
# ### BEGIN ### API Event Methods ### update_event_obj() ### # ### BEGIN ### API Event Methods ### update_event_obj() ###
def update_event_obj( def update_event_obj(
event_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. event_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.

View File

@@ -39,8 +39,9 @@ def create_post_comment_obj(post_comment_obj_new:Post_Comment_Base):
# ### BEGIN ### API Post Comment Methods ### load_post_comment_obj() ### # ### BEGIN ### API Post Comment Methods ### load_post_comment_obj() ###
def load_post_comment_obj( def load_post_comment_obj(
post_comment_id: int|str, post_comment_id: int|str,
enabled: str = 'enabled', # enabled, disabled, all
limit: int = 1000, limit: int = 1000,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_person: bool = False, inc_person: bool = False,
inc_user: bool = False, inc_user: bool = False,
) -> Post_Comment_Base|bool: ) -> Post_Comment_Base|bool:
@@ -83,10 +84,86 @@ def load_post_comment_obj(
post_comment_obj.user = user_obj post_comment_obj.user = user_obj
else: post_comment_obj.user = None else: post_comment_obj.user = None
return post_comment_obj if model_as_dict:
return post_comment_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
else:
return post_comment_obj
# ### END ### API Post Comment Methods ### load_post_comment_obj() ### # ### END ### API Post Comment Methods ### load_post_comment_obj() ###
# ### BEGIN ### API Post Comment Methods ### load_post_comment_obj_list() ###
def load_post_comment_obj_list(
post_id: int|str,
limit: int = 1000,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_person: bool = False,
inc_user: bool = False,
) -> list|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if post_id := redis_lookup_id_random(record_id_random=post_id, table_name='post'): pass
else: return False
data = {}
data['post_id'] = post_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 = ''
# else: tbl_obj['post'] = None
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `tbl`.id AS 'post_comment_id', `tbl`.id_random AS 'post_comment_id_random'
FROM `post_comment` AS `tbl`
WHERE `tbl`.post_id = :post_id
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
if post_comment_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_comment_rec_li_result)
post_comment_result_li = []
for post_comment_rec in post_comment_rec_li_result:
post_comment_id = post_comment_rec.get('post_comment_id', None)
if post_comment_result := load_post_comment_obj(
post_comment_id = post_comment_id,
model_as_dict = model_as_dict,
# enabled = enabled,
inc_person = inc_person,
inc_user = inc_user,
):
log.debug(post_comment_result)
post_comment_result_li.append(post_comment_result)
else:
log.debug(post_comment_result)
post_comment_result_li.append(None)
log.debug(post_comment_result_li)
else:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_comment_rec_li_result)
post_comment_result_li = []
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
return post_comment_result_li
# ### END ### API Post Comment Methods ### load_post_comment_obj_list() ###
# ### BEGIN ### API Post Comment Methods ### update_post_comment_obj() ### # ### BEGIN ### API Post Comment Methods ### update_post_comment_obj() ###
def update_post_comment_obj( def update_post_comment_obj(
post_comment_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. post_comment_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.

View File

@@ -40,8 +40,9 @@ def create_post_obj(post_obj_new:Post_Base):
# ### BEGIN ### API Post Methods ### load_post_obj() ### # ### BEGIN ### API Post Methods ### load_post_obj() ###
def load_post_obj( def load_post_obj(
post_id: int|str, post_id: int|str,
enabled: str = 'enabled', # enabled, disabled, all
limit: int = 1000, limit: int = 1000,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_post_comment_list: bool = False, inc_post_comment_list: bool = False,
inc_person: bool = False, inc_person: bool = False,
inc_user: bool = False, inc_user: bool = False,
@@ -77,59 +78,16 @@ def load_post_obj(
else: post_obj.person = None else: post_obj.person = None
if inc_post_comment_list: if inc_post_comment_list:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL if post_comment_dict_list := load_post_comment_obj_list(
post_id = post_id,
data = {} limit = limit,
data['post_id'] = post_id model_as_dict = True,
enabled = enabled,
if enabled in ['enabled', 'disabled', 'all']: inc_person = inc_person,
if enabled == 'enabled': inc_user = inc_user,
data['enable'] = True ):
sql_enabled = f'AND `post_comment`.enable = :enable' post_obj.post_comment_list = post_comment_dict_list
elif enabled == 'disabled': else: post_obj.post_comment_list = None
data['enable'] = False
sql_enabled = f'AND `post_comment`.enable = :enable'
elif enabled == 'all':
sql_enabled = ''
# else: event_obj['post'] = None
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `post_comment`.id AS 'post_comment_id', `post_comment`.id_random AS 'post_comment_id_random'
FROM `post_comment` AS `post_comment`
WHERE `post_comment`.post_id = :post_id
{sql_enabled}
ORDER BY `post_comment`.created_on DESC, `post_comment`.updated_on DESC
{sql_limit};
"""
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if post_comment_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
#log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_comment_rec_li_result)
post_comment_obj_li = []
for post_comment_rec in post_comment_rec_li_result:
post_comment_id = post_comment_rec.get('post_comment_id', None)
if post_comment_obj := load_post_comment_obj(
post_comment_id=post_comment_id,
enabled=enabled,
inc_person=inc_person,
inc_user=inc_user
):
data = post_comment_obj.dict(by_alias=True, exclude_unset=True)
post_comment_obj_li.append(data)
log.debug(post_comment_obj_li)
post_obj.post_comment_list = post_comment_obj_li
else:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_comment_rec_li_result)
post_obj.post_comment_list = []
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
if inc_user: if inc_user:
user_id = post_rec.get('user_id', None) user_id = post_rec.get('user_id', None)
@@ -141,10 +99,88 @@ def load_post_obj(
post_obj.user = user_obj post_obj.user = user_obj
else: post_obj.user = None else: post_obj.user = None
return post_obj if model_as_dict:
return post_obj.dict(by_alias=True, exclude_unset=True) # pylint: disable=no-member
else:
return post_obj
# ### END ### API Post Methods ### load_post_obj() ### # ### END ### API Post Methods ### load_post_obj() ###
# ### BEGIN ### API Post Methods ### load_post_obj_list() ###
def load_post_obj_list(
account_id: int|str,
limit: int = 1000,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
inc_post_comment_list: bool = False,
inc_person: bool = False,
inc_user: bool = False,
) -> list|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
data = {}
data['account_id'] = account_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 = ''
# else: tbl_obj['account'] = None
if limit:
data['limit'] = limit
sql_limit = f'LIMIT :limit'
else:
sql_limit = ''
sql = f"""
SELECT `tbl`.id AS 'post_id', `tbl`.id_random AS 'post_id_random'
FROM `post` AS `tbl`
WHERE `tbl`.account_id = :account_id
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_limit};
"""
if post_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_rec_li_result)
post_result_li = []
for post_rec in post_rec_li_result:
post_id = post_rec.get('post_id', None)
if post_result := load_post_obj(
post_id = post_id,
model_as_dict = model_as_dict,
enabled = enabled,
inc_post_comment_list = inc_post_comment_list,
inc_person = inc_person,
inc_user = inc_user,
):
log.debug(post_result)
post_result_li.append(post_result)
else:
log.debug(post_result)
post_result_li.append(None)
log.debug(post_result_li)
else:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_rec_li_result)
post_result_li = []
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
return post_result_li
# ### END ### API Post Methods ### load_post_obj_list() ###
# ### BEGIN ### API Post Methods ### update_post_obj() ### # ### BEGIN ### API Post Methods ### update_post_obj() ###
def update_post_obj( def update_post_obj(
post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value. post_id: int|str, # Ideally the int ID should be passed. This allows for updating of the id_random value.

View File

@@ -91,7 +91,7 @@ async def get_account_obj_li(
return result return result
# ### BEGIN ### API Account ### get_account_obj() ### # ### BEGIN ### API Account ### get_account_obj_new() ###
# Working well as of 2021-06-11. Using as a template for other routes. # Working well as of 2021-06-11. Using as a template for other routes.
@router.get('/{account_id}', response_model=Resp_Body_Base) @router.get('/{account_id}', response_model=Resp_Body_Base)
async def get_account_obj_new( async def get_account_obj_new(
@@ -152,6 +152,8 @@ async def get_account_obj_new(
inc_person_list: bool = False, inc_person_list: bool = False,
# inc_post: bool = False, # inc_post: bool = False,
inc_post_list: bool = False, # Priority l1 inc_post_list: bool = False, # Priority l1
# inc_post_comment: bool = False,
inc_post_comment_list: bool = False,
# inc_product: bool = False, # inc_product: bool = False,
inc_product_list: bool = False, inc_product_list: bool = False,
# inc_site: bool = False, # inc_site: bool = False,
@@ -230,7 +232,7 @@ async def get_account_obj_new(
return mk_resp(data=False, status_code=400) # Bad Request return mk_resp(data=False, status_code=400) # Bad Request
return mk_resp(data=response_data) return mk_resp(data=response_data)
# ### END ### API Account ### get_account_obj() ### # ### END ### API Account ### get_account_obj_new() ###
@router.get('/{obj_id}', response_model=Resp_Body_Base) @router.get('/{obj_id}', response_model=Resp_Body_Base)

View File

@@ -558,6 +558,141 @@ async def lookup_username(
return mk_resp(data=data) return mk_resp(data=data)
# ### BEGIN ### API User ### get_user_obj_new() ###
# Working well as of 2021-06-11. Using as a template for other routes.
@router.get('/{user_id}', response_model=Resp_Body_Base)
async def get_user_obj_new(
account_id: str = Query(..., min_length=1, max_length=22),
limit: int = 500, # For now this covers any included objects or object lists
enabled: str = 'enabled', # For now this covers any included objects or object lists
inc_account_cfg: bool = False, # Priority l1
inc_address: bool = False, # Under contact
inc_contact: bool = False,
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_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_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_hosted_file_list: bool = False,
inc_journal_list: bool = False,
# inc_membership: bool = False,
inc_membership_list: bool = False,
# inc_order: bool = False,
inc_order_list: bool = False,
# inc_order_cart: bool = False,
inc_order_cart_list: bool = False,
inc_organization: bool = False,
inc_organization_list: bool = False,
inc_person: bool = False,
inc_person_list: bool = False,
# 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,
# inc_site: bool = False,
# inc_site_list: bool = False,
inc_user: bool = False,
inc_user_list: bool = False,
x_account_id: str = Header(...),
by_alias: Optional[bool] = True,
exclude_unset: Optional[bool] = True,
):
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 mk_resp(data=None, status_code=404)
if account_dict := load_user_obj(
account_id = account_id,
enabled = enabled,
limit = limit,
model_as_dict = True, # NOTE: returning model as a dict
inc_address = inc_address,
# inc_address_list = inc_address_list,
# inc_archive = inc_archive,
# inc_archive_list = inc_archive_list,
# inc_archive_content = inc_archive_content,
# inc_archive_content_list = inc_archive_content_list,
inc_contact = inc_contact,
inc_contact_list = inc_contact_list,
inc_event = inc_event,
inc_event_list = inc_event_list,
# 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_file_list = inc_event_file_list,
# inc_event_location = inc_event_location,
# inc_event_person = inc_event_person,
inc_event_person_list = inc_event_person_list,
inc_event_presentation_list = inc_event_presentation_list,
# inc_event_presenter_cat = inc_event_presenter_cat,
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 = inc_event_track,
# inc_event_track_list = inc_event_track_list,
# inc_fundraising_cfg = inc_fundraising_cfg,
inc_hosted_file_list = inc_hosted_file_list,
inc_journal_list = inc_journal_list,
inc_membership = inc_membership,
# inc_membership_cfg = inc_membership_cfg,
# inc_membership_list = inc_membership_list,
inc_order = inc_order,
inc_order_list = inc_order_list,
inc_order_cart = inc_order_cart,
inc_order_cart_list = inc_order_cart_list,
inc_organization = inc_organization,
inc_organization_list = inc_organization_list,
inc_person = inc_person,
inc_person_list = inc_person_list,
inc_post = inc_post,
inc_post_list = inc_post_list,
# inc_product = inc_product,
# inc_product_list = inc_product_list,
# inc_site = inc_site,
# inc_site_list = inc_site_list,
# inc_user = inc_user,
# inc_user_list = inc_user_list,
):
if isinstance(account_dict, dict):
response_data = account_dict
else:
response_data = account_dict
else:
return mk_resp(data=False, status_code=400) # Bad Request
return mk_resp(data=response_data)
# ### END ### API User ### get_user_obj() ###
@router.get('/{user_id}', response_model=Resp_Body_Base) @router.get('/{user_id}', response_model=Resp_Body_Base)
async def get_user_obj( async def get_user_obj(
user_id: str = Query(..., min_length=1, max_length=22), user_id: str = Query(..., min_length=1, max_length=22),