feat: add getProfMailById method to retrieve professor's email by ID
refactor: reorganize import statements and clean up commented code
This commit is contained in:
@@ -12,7 +12,7 @@ from typing import Any, List, Optional, Tuple, Union
|
|||||||
|
|
||||||
import loguru
|
import loguru
|
||||||
|
|
||||||
from src import LOG_DIR, settings, DATABASE_DIR
|
from src import DATABASE_DIR, LOG_DIR, settings
|
||||||
from src.backend.db import (
|
from src.backend.db import (
|
||||||
CREATE_ELSA_FILES_TABLE,
|
CREATE_ELSA_FILES_TABLE,
|
||||||
CREATE_ELSA_MEDIA_TABLE,
|
CREATE_ELSA_MEDIA_TABLE,
|
||||||
@@ -38,7 +38,6 @@ log.add(sys.stdout, level="INFO")
|
|||||||
log.add(f"{LOG_DIR}/application.log", rotation="1 MB", retention="10 days")
|
log.add(f"{LOG_DIR}/application.log", rotation="1 MB", retention="10 days")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ascii_lowercase = lower + digits + punctuation
|
ascii_lowercase = lower + digits + punctuation
|
||||||
|
|
||||||
|
|
||||||
@@ -201,12 +200,12 @@ class Database:
|
|||||||
logs_query = query
|
logs_query = query
|
||||||
|
|
||||||
logs_args = args
|
logs_args = args
|
||||||
if "fileblob" in query:
|
# if "fileblob" in query:
|
||||||
# set fileblob arg in logger to "too long"
|
# # set fileblob arg in logger to "too long"
|
||||||
logs_query = query
|
# logs_query = query
|
||||||
fileblob_location = query.find("fileblob")
|
# fileblob_location = query.find("fileblob")
|
||||||
# remove fileblob from query
|
# # remove fileblob from query
|
||||||
logs_query = query[:fileblob_location] + "fileblob = too long"
|
# logs_query = query[:fileblob_location] + "fileblob = too long"
|
||||||
|
|
||||||
log_message = f"Querying database with query {logs_query}, args: {logs_args}"
|
log_message = f"Querying database with query {logs_query}, args: {logs_args}"
|
||||||
# if "INSERT" in query:
|
# if "INSERT" in query:
|
||||||
@@ -435,6 +434,7 @@ class Database:
|
|||||||
deleted (int, optional): The state of the book. Set to 1 to include deleted ones. Defaults to 0.
|
deleted (int, optional): The state of the book. Set to 1 to include deleted ones. Defaults to 0.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
list[dict[int, BookData, int]]: A list of dictionaries containing the id, the metadata of the book and the availability of the book
|
list[dict[int, BookData, int]]: A list of dictionaries containing the id, the metadata of the book and the availability of the book
|
||||||
"""
|
"""
|
||||||
qdata = self.query_db(
|
qdata = self.query_db(
|
||||||
@@ -525,11 +525,12 @@ class Database:
|
|||||||
str: The filename of the recreated file
|
str: The filename of the recreated file
|
||||||
"""
|
"""
|
||||||
blob = self.getBlob(filename, app_id)
|
blob = self.getBlob(filename, app_id)
|
||||||
|
log.debug(blob)
|
||||||
tempdir = settings.database.temp.expanduser()
|
tempdir = settings.database.temp.expanduser()
|
||||||
if not tempdir.exists():
|
if not tempdir.exists():
|
||||||
tempdir.mkdir(parents=True, exist_ok=True)
|
tempdir.mkdir(parents=True, exist_ok=True)
|
||||||
file = tempfile.NamedTemporaryFile(
|
file = tempfile.NamedTemporaryFile(
|
||||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
delete=False, dir=tempdir, mode="wb", suffix=f".{filetype}"
|
||||||
)
|
)
|
||||||
file.write(blob)
|
file.write(blob)
|
||||||
# log.debug("file created")
|
# log.debug("file created")
|
||||||
@@ -701,6 +702,20 @@ class Database:
|
|||||||
else:
|
else:
|
||||||
return prof[0]
|
return prof[0]
|
||||||
|
|
||||||
|
def getProfMailById(self, prof_id: Union[str, int]) -> str:
|
||||||
|
"""get the mail of a professor based on the id
|
||||||
|
|
||||||
|
Args:
|
||||||
|
prof_id (Union[str,int]): the id of the professor
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: the mail of the professor
|
||||||
|
"""
|
||||||
|
mail = self.query_db("SELECT mail FROM prof WHERE id=?", (prof_id,), one=True)[
|
||||||
|
0
|
||||||
|
]
|
||||||
|
return mail if mail is not None else ""
|
||||||
|
|
||||||
def getTitleById(self, prof_id: Union[str, int]) -> str:
|
def getTitleById(self, prof_id: Union[str, int]) -> str:
|
||||||
"""get the title of a professor based on the id
|
"""get the title of a professor based on the id
|
||||||
|
|
||||||
@@ -1701,4 +1716,4 @@ class Database:
|
|||||||
cursor.execute(query, args)
|
cursor.execute(query, args)
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
connection.close()
|
connection.close()
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user