merge main into dev #13

Merged
WorldTeacher merged 41 commits from main into dev 2025-09-03 09:44:13 +01:00
Showing only changes of commit 7da2b3f65d - Show all commits

View File

@@ -12,7 +12,7 @@ from typing import Any, List, Optional, Tuple, Union
import loguru
from src import LOG_DIR, settings, DATABASE_DIR
from src import DATABASE_DIR, LOG_DIR, settings
from src.backend.db import (
CREATE_ELSA_FILES_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")
ascii_lowercase = lower + digits + punctuation
@@ -201,12 +200,12 @@ class Database:
logs_query = query
logs_args = args
if "fileblob" in query:
# set fileblob arg in logger to "too long"
logs_query = query
fileblob_location = query.find("fileblob")
# remove fileblob from query
logs_query = query[:fileblob_location] + "fileblob = too long"
# if "fileblob" in query:
# # set fileblob arg in logger to "too long"
# logs_query = query
# fileblob_location = query.find("fileblob")
# # remove fileblob from query
# logs_query = query[:fileblob_location] + "fileblob = too long"
log_message = f"Querying database with query {logs_query}, args: {logs_args}"
# 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.
Returns:
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(
@@ -525,11 +525,12 @@ class Database:
str: The filename of the recreated file
"""
blob = self.getBlob(filename, app_id)
log.debug(blob)
tempdir = settings.database.temp.expanduser()
if not tempdir.exists():
tempdir.mkdir(parents=True, exist_ok=True)
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)
# log.debug("file created")
@@ -701,6 +702,20 @@ class Database:
else:
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:
"""get the title of a professor based on the id
@@ -1701,4 +1716,4 @@ class Database:
cursor.execute(query, args)
result = cursor.fetchone()
connection.close()
return result
return result