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)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ CREATE_TABLE_APPARAT = """CREATE TABLE semesterapparat (
|
||||
deleted_date TEXT,
|
||||
apparat_id_adis INTEGER,
|
||||
prof_id_adis INTEGER,
|
||||
konto INTEGER REFERENCES app_kontos (id),
|
||||
konto INTEGER,
|
||||
FOREIGN KEY (prof_id) REFERENCES prof (id)
|
||||
)"""
|
||||
CREATE_TABLE_MEDIA = """CREATE TABLE media (
|
||||
@@ -26,13 +26,7 @@ CREATE_TABLE_MEDIA = """CREATE TABLE media (
|
||||
FOREIGN KEY (prof_id) REFERENCES prof (id),
|
||||
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
|
||||
)"""
|
||||
CREATE_TABLE_APPKONTOS = """CREATE TABLE app_kontos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
app_id INTEGER,
|
||||
konto INTEGER,
|
||||
passwort TEXT,
|
||||
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
|
||||
)"""
|
||||
|
||||
CREATE_TABLE_FILES = """CREATE TABLE files (
|
||||
id INTEGER PRIMARY KEY,
|
||||
filename TEXT,
|
||||
|
||||
@@ -119,10 +119,16 @@ class Semester:
|
||||
return True
|
||||
return False
|
||||
|
||||
def from_string(self, val):
|
||||
self.value = val
|
||||
self._year = int(val[-2:])
|
||||
self._semester = val[:4]
|
||||
def from_string(self, val: str):
|
||||
if " " in val:
|
||||
values = val.split(" ")
|
||||
if len(values) != 2:
|
||||
raise ValueError("Invalid semester format")
|
||||
self._semester = values[0]
|
||||
if len(values[1]) == 4:
|
||||
self._year = int(values[1][2:])
|
||||
# self._year = int(values[1])
|
||||
self.computeValue()
|
||||
return self
|
||||
|
||||
@property
|
||||
|
||||
@@ -5,7 +5,19 @@ from PyQt6.QtCore import QThread
|
||||
from PyQt6.QtCore import pyqtSignal as Signal
|
||||
|
||||
from src.backend import Database
|
||||
from loguru import logger as log
|
||||
import sys
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/application.log", rotation="1 week", enqueue=True)
|
||||
log.add(
|
||||
"logs/autoadder.log",
|
||||
compression="zip",
|
||||
)
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
logger.add(sys.stdout)
|
||||
|
||||
# from src.transformers import RDS_AVAIL_DATA
|
||||
|
||||
|
||||
@@ -9,6 +9,18 @@ from src.backend.database import Database
|
||||
from src.logic.webrequest import BibTextTransformer, WebRequest
|
||||
|
||||
# from src.transformers import RDS_AVAIL_DATA
|
||||
from loguru import logger as log
|
||||
import sys
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/application.log", rotation="1 week", enqueue=True)
|
||||
log.add(
|
||||
"logs/availthread.log",
|
||||
)
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
logger.add(sys.stdout)
|
||||
|
||||
|
||||
class AvailChecker(QThread):
|
||||
|
||||
Reference in New Issue
Block a user