Work on lots of methods and models.

This commit is contained in:
Scott Idem
2021-06-17 17:53:55 -04:00
parent c17724cea1
commit 47ce2380be
13 changed files with 535 additions and 359 deletions

View File

@@ -227,3 +227,58 @@ def update_post_comment_obj(
log.debug(post_comment_obj_up_result)
return False
# ### END ### API Post Comment Methods ### update_post_comment_obj() ###
# ### BEGIN ### API Post Comment Methods ### get_post_comment_rec_list() ###
def get_post_comment_rec_list(
for_obj_type: str,
for_obj_id: str,
limit: int = 1000,
enabled: str = 'enabled', # enabled, disabled, all
) -> list|bool:
log.setLevel(logging.WARNING) # 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
data = {}
data[f'{for_obj_type}_id'] = for_obj_id
# data['for_obj_type'] = for_obj_type
sql_obj_type_id = f'`tbl`.{for_obj_type}_id = :{for_obj_type}_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 = ''
sql_enabled = ''
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
{sql_obj_type_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):
post_comment_rec_li = post_comment_rec_li_result
else:
post_comment_rec_li = []
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(post_comment_rec_li_result)
return post_comment_rec_li
# ### END ### API Post Comment Methods ### get_post_comment_rec_list() ###