Work on file uploads and listing event files.

This commit is contained in:
Scott Idem
2021-06-15 18:05:56 -04:00
parent 415e452988
commit 0dc50e4509
12 changed files with 841 additions and 222 deletions

View File

@@ -74,6 +74,8 @@ def sql_insert(sql:str|None=None, data:dict|None=None, table_name:str|None=None,
result_insert = db.execute(sql_insert, data)
trans.commit()
except Exception as e:
# http://sqlalche.me/e/14/gkpj
# Need a check for this: sqlalchemy.exc.IntegrityError: (MySQLdb._exceptions.IntegrityError) (1062, "Duplicate entry 'z-yyyy-xxxx-wwww for key 'PRIMARY'"
trans.rollback()
log.exception('*** An exception happened. ***')
log.exception(repr(e))
@@ -514,7 +516,7 @@ def sql_delete(
sql:str|None=None,
data:dict|None=None
):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
if table_name and (record_id or record_id_random) and not (field_name or field_value or sql or data):
@@ -735,7 +737,43 @@ def redis_lookup_id_random(record_id_random:int|str, table_name:str):
log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.error('We should not be here. Something unexpected happened.')
return False # Just in case
# ### BEGIN ### API Lib General ### redis_lookup_id_random() ###
# ### END ### API Lib General ### redis_lookup_id_random() ###
# ### BEGIN ### API Lib General ### lookup_id_random() ###
def lookup_id_random(record_id:int, table_name:str):
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
data = { 'id': record_id }
sql = f"""
SELECT id_random
FROM `{table_name}` AS `table`
WHERE `table`.id = :id;
"""
if select_results := sql_select(sql=sql, data=data):
#log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(select_results)
log.debug(type(select_results))
if isinstance(select_results, dict):
log.info(f"""Record ID found: {str(select_results['id_random'])}""")
if record_id_random := select_results.get('id_random'):
return str(record_id_random)
else:
log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.error('The SQL result was not what was expected.')
return False
else:
log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.error('More than one record may have been found. There may be a duplicate id.')
log.error(select_results)
return False
else:
#log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.info('Record ID random was not found')
return None
# ### END ### API Lib General ### lookup_id_random() ###
# ### BEGIN ### API Lib General ### lookup_id_random_pop() ###