Work on archives

This commit is contained in:
Scott Idem
2021-11-01 17:17:02 -04:00
parent f31626f51c
commit 82a6cb4525
5 changed files with 80 additions and 18 deletions

View File

@@ -51,6 +51,9 @@ def get_archive_content_rec_list(
for_obj_id: str,
limit: int = 1000,
enabled: str = 'enabled', # enabled, disabled, all
sort_by_str: str = None,
sort_by: str = None,
sort_by_desc: bool = False,
) -> list|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -78,13 +81,20 @@ def get_archive_content_rec_list(
else:
sql_limit = ''
if sort_by:
sql_order_by = f'ORDER BY `tbl`.{sort_by}'
if sort_by_desc:
sql_order_by = f'{sql_order_by} {DESC}'
else:
sql_order_by = 'ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC'
sql = f"""
SELECT `tbl`.id AS 'archive_content_id', `tbl`.id_random AS 'archive_content_id_random'
FROM `archive_content` AS `tbl`
WHERE
{sql_obj_type_id}
{sql_enabled}
ORDER BY `tbl`.created_on DESC, `tbl`.updated_on DESC
{sql_order_by}
{sql_limit};
"""

View File

@@ -20,6 +20,7 @@ def load_archive_obj(
exclude_unset: bool = True,
model_as_dict: bool = False,
enabled: str = 'enabled', # enabled, disabled, all
hidden: str = 'not_hidden', # hidden, not_hidden, all
inc_archive_content_list: bool = False,
) -> Archive_Base|dict|bool:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
@@ -42,11 +43,15 @@ def load_archive_obj(
# Updated 2021-06-18
if inc_archive_content_list:
sort_by = archive_rec.get('sort_by')
sort_by_desc = archive_rec.get('sort_by_desc')
if archive_content_rec_list_result := get_archive_content_rec_list(
for_obj_type = 'archive',
for_obj_id = archive_id,
limit = limit,
enabled = enabled,
sort_by = sort_by,
sort_by_desc = sort_by_desc,
):
archive_content_result_list = []
for archive_content_rec in archive_content_rec_list_result: