update logging, update docuprint add new ui for generating documents
This commit is contained in:
@@ -11,7 +11,6 @@ from src.backend.db import (
|
||||
CREATE_ELSA_MEDIA_TABLE,
|
||||
CREATE_ELSA_TABLE,
|
||||
CREATE_TABLE_APPARAT,
|
||||
CREATE_TABLE_APPKONTOS,
|
||||
CREATE_TABLE_FILES,
|
||||
CREATE_TABLE_MEDIA,
|
||||
CREATE_TABLE_MESSAGES,
|
||||
@@ -136,7 +135,6 @@ class Database:
|
||||
cursor.execute(CREATE_TABLE_APPARAT)
|
||||
cursor.execute(CREATE_TABLE_MESSAGES)
|
||||
cursor.execute(CREATE_TABLE_MEDIA)
|
||||
cursor.execute(CREATE_TABLE_APPKONTOS)
|
||||
cursor.execute(CREATE_TABLE_FILES)
|
||||
cursor.execute(CREATE_TABLE_PROF)
|
||||
cursor.execute(CREATE_TABLE_USER)
|
||||
@@ -164,8 +162,11 @@ class Database:
|
||||
|
||||
@logger.catch
|
||||
def query_db(
|
||||
self, query: str, args: Tuple = (), one: bool = False
|
||||
) -> Union[Tuple, List[Tuple]]:
|
||||
self,
|
||||
query: str,
|
||||
args: Tuple[Any, Any] = (), # type:ignore
|
||||
one: bool = False, # type:ignore
|
||||
) -> Union[Tuple[Any, Any], List[Tuple[Any, Any]]]:
|
||||
"""
|
||||
Query the Database for the sent query.
|
||||
|
||||
@@ -180,6 +181,7 @@ class Database:
|
||||
conn = self.connect()
|
||||
cursor = conn.cursor()
|
||||
logs_query = query
|
||||
|
||||
logs_args = args
|
||||
if "fileblob" in query:
|
||||
# set fileblob arg in logger to "too long"
|
||||
@@ -448,7 +450,7 @@ class Database:
|
||||
self.query_db("UPDATE media SET deleted=1 WHERE id=?", (book_id,))
|
||||
|
||||
# File Interactions
|
||||
def getBlob(self, filename, app_id: Union[str, int]):
|
||||
def getBlob(self, filename: str, app_id: Union[str, int]) -> bytes:
|
||||
"""
|
||||
Get a blob from the database
|
||||
|
||||
@@ -706,6 +708,18 @@ class Database:
|
||||
query += " FROM prof WHERE id=?"
|
||||
return self.query_db(query, (prof_id,), one=True)[0]
|
||||
|
||||
def getProfById(self, prof_id: Union[str, int]) -> Prof:
|
||||
"""Get a professor based on the id
|
||||
|
||||
Args:
|
||||
prof_id (Union[str,int]): the id of the professor
|
||||
|
||||
Returns:
|
||||
Prof: a Prof object containing the data of the professor
|
||||
"""
|
||||
data = self.query_db("SELECT * FROM prof WHERE id=?", (prof_id,), one=True)
|
||||
return Prof().from_tuple(data)
|
||||
|
||||
def getProfData(self, profname: str):
|
||||
"""Get mail, telephone number and title of a professor based on the name
|
||||
|
||||
@@ -881,7 +895,7 @@ class Database:
|
||||
self.query_db(query)
|
||||
return None
|
||||
|
||||
def getApparatsByProf(self, prof_id: Union[str, int]) -> list[tuple]:
|
||||
def getApparatsByProf(self, prof_id: Union[str, int]) -> list[Apparat]:
|
||||
"""Get all apparats based on the professor id
|
||||
|
||||
Args:
|
||||
@@ -1432,7 +1446,7 @@ class Database:
|
||||
"SELECT fileblob FROM elsa_files WHERE filename=?", (filename,), one=True
|
||||
)[0]
|
||||
# logger.debug(blob)
|
||||
tempdir = self.database.tempdir
|
||||
tempdir = self.database.temp
|
||||
tempdir = tempdir.replace("~", str(Path.home()))
|
||||
tempdir_path = Path(tempdir)
|
||||
if not os.path.exists(tempdir_path):
|
||||
@@ -1450,9 +1464,11 @@ class Database:
|
||||
Returns:
|
||||
list[tuple]: a list of tuples containing the ELSA apparats
|
||||
"""
|
||||
return self.query_db("SELECT * FROM elsa")
|
||||
return self.query_db(
|
||||
"SELECT * FROM elsa ORDER BY substr(date, 7, 4) || '-' || substr(date, 4, 2) || '-' || substr(date, 1, 2)"
|
||||
)
|
||||
|
||||
def getElsaId(self, prof_id, semester, date):
|
||||
def getElsaId(self, prof_id: int, semester: str, date: str) -> int:
|
||||
"""get the id of an ELSA apparat based on the professor, semester and date
|
||||
|
||||
Args:
|
||||
@@ -1534,9 +1550,7 @@ class Database:
|
||||
"""
|
||||
conn = self.connect()
|
||||
cursor = conn.cursor()
|
||||
if isinstance(profdata, Prof):
|
||||
fullname = profdata.name()
|
||||
else:
|
||||
if isinstance(profdata, dict):
|
||||
name = profdata["profname"]
|
||||
if "," in name:
|
||||
fname = name.split(", ")[1].strip()
|
||||
@@ -1544,6 +1558,8 @@ class Database:
|
||||
fullname = f"{lname} {fname}"
|
||||
else:
|
||||
fullname = profdata["profname"]
|
||||
else:
|
||||
fullname = profdata.name()
|
||||
query = f"SELECT id FROM prof WHERE fullname = '{fullname}'"
|
||||
logger.debug(query)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user