Work on lots of methods and models.
This commit is contained in:
@@ -9,7 +9,7 @@ from app.lib_general import log, logging
|
||||
|
||||
from app.methods.person_methods import load_person_obj
|
||||
# from app.methods.post_comment_methods import create_post_comment_obj, update_post_comment_obj
|
||||
from app.methods.post_comment_methods import load_post_comment_obj_list
|
||||
from app.methods.post_comment_methods import get_post_comment_rec_list, load_post_comment_obj
|
||||
# from app.methods.user_methods import load_user_obj
|
||||
|
||||
from app.models.post_models import Post_Base
|
||||
@@ -78,17 +78,40 @@ def load_post_obj(
|
||||
post_obj.person = person_obj
|
||||
else: post_obj.person = None
|
||||
|
||||
# Updated 2021-06-17
|
||||
if inc_post_comment_list:
|
||||
if post_comment_dict_list := load_post_comment_obj_list(
|
||||
post_id = post_id,
|
||||
limit = limit,
|
||||
model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
):
|
||||
if post_comment_rec_list_result := get_post_comment_rec_list(
|
||||
for_obj_type = 'post',
|
||||
for_obj_id = post_id,
|
||||
limit = limit,
|
||||
enabled = enabled,
|
||||
):
|
||||
post_comment_dict_list = []
|
||||
for post_comment_rec in post_comment_rec_list_result:
|
||||
post_comment_dict_list.append(
|
||||
load_post_comment_obj(
|
||||
post_comment_id = post_comment_rec.get('post_comment_id', None),
|
||||
limit = limit,
|
||||
model_as_dict = model_as_dict,
|
||||
enabled = enabled,
|
||||
inc_person = inc_person,
|
||||
inc_user = inc_user,
|
||||
)
|
||||
)
|
||||
post_obj.post_comment_list = post_comment_dict_list
|
||||
else: post_obj.post_comment_list = None
|
||||
else: post_obj.post_comment_list = []
|
||||
|
||||
# if inc_post_comment_list:
|
||||
# if post_comment_dict_list := load_post_comment_obj_list(
|
||||
# post_id = post_id,
|
||||
# limit = limit,
|
||||
# model_as_dict = model_as_dict,
|
||||
# enabled = enabled,
|
||||
# inc_person = inc_person,
|
||||
# inc_user = inc_user,
|
||||
# ):
|
||||
# post_obj.post_comment_list = post_comment_dict_list
|
||||
# else: post_obj.post_comment_list = None
|
||||
|
||||
if inc_user:
|
||||
user_id = post_rec.get('user_id', None)
|
||||
@@ -250,3 +273,57 @@ def update_post_obj(
|
||||
log.debug(post_obj_up_result)
|
||||
return False
|
||||
# ### END ### API Post Methods ### update_post_obj() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Post Methods ### get_post_rec_list() ###
|
||||
def get_post_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 = ''
|
||||
|
||||
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
|
||||
{sql_obj_type_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):
|
||||
post_rec_li = post_rec_li_result
|
||||
else:
|
||||
post_rec_li = []
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(post_rec_li_result)
|
||||
|
||||
return post_rec_li
|
||||
# ### END ### API Post Methods ### get_post_rec_list() ###
|
||||
|
||||
Reference in New Issue
Block a user