add type checking, update deletion function in searchpage, add function to import apparat data from document
This commit is contained in:
@@ -30,11 +30,9 @@ from loguru import logger as log
|
||||
|
||||
logger = log
|
||||
logger.remove()
|
||||
logger.add("logs/database.log", rotation="1 week", enqueue=True)
|
||||
logger.add("logs/application.log", rotation="1 week", enqueue=True)
|
||||
log.add(
|
||||
"logs/application.log",
|
||||
rotation="1 day",
|
||||
compression="zip",
|
||||
"logs/database.log",
|
||||
)
|
||||
|
||||
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
@@ -72,7 +70,7 @@ class Database:
|
||||
path = os.path.abspath(path)
|
||||
if not os.path.exists(path):
|
||||
# create path
|
||||
# print(path)
|
||||
# logger.debug(path)
|
||||
os.makedirs(path)
|
||||
if self.get_db_contents() == []:
|
||||
logger.critical("Database does not exist, creating tables")
|
||||
@@ -227,11 +225,11 @@ class Database:
|
||||
f"SELECT bookdata FROM media WHERE app_id={app_id} AND prof_id={prof_id}"
|
||||
)
|
||||
logger.debug(t_query)
|
||||
# # print(t_query)
|
||||
# # logger.debug(t_query)
|
||||
result = cursor.execute(t_query).fetchall()
|
||||
result = [load_pickle(i[0]) for i in result]
|
||||
if bookdata in result:
|
||||
# print("Bookdata already in database")
|
||||
# logger.debug("Bookdata already in database")
|
||||
# check if the book was deleted in the apparat
|
||||
query = (
|
||||
"SELECT deleted FROM media WHERE app_id=? AND prof_id=? AND bookdata=?"
|
||||
@@ -239,7 +237,7 @@ class Database:
|
||||
params = (app_id, prof_id, dump_pickle(bookdata))
|
||||
result = cursor.execute(query, params).fetchone()
|
||||
if result[0] == 1:
|
||||
# print("Book was deleted, updating bookdata")
|
||||
# logger.debug("Book was deleted, updating bookdata")
|
||||
query = "UPDATE media SET deleted=0 WHERE app_id=? AND prof_id=? AND bookdata=?"
|
||||
params = (app_id, prof_id, dump_pickle(bookdata))
|
||||
cursor.execute(query, params)
|
||||
@@ -511,7 +509,7 @@ class Database:
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
file.write(blob)
|
||||
# print("file created")
|
||||
# logger.debug("file created")
|
||||
return file.name
|
||||
|
||||
def getFiles(self, app_id: Union[str, int], prof_id: int) -> list[tuple]:
|
||||
@@ -539,7 +537,7 @@ class Database:
|
||||
return [i[0] for i in data]
|
||||
|
||||
def insertSubjects(self):
|
||||
# print("Inserting subjects")
|
||||
# logger.debug("Inserting subjects")
|
||||
subjects = [
|
||||
"Biologie",
|
||||
"Chemie",
|
||||
@@ -897,7 +895,7 @@ class Database:
|
||||
)
|
||||
ret = []
|
||||
for i in data:
|
||||
print(i)
|
||||
logger.debug(i)
|
||||
ret.append(Apparat().from_tuple(i))
|
||||
return ret
|
||||
|
||||
@@ -1110,9 +1108,9 @@ class Database:
|
||||
kwargs["dauer"] = kwargs["dauer"].replace("Ja", "1").replace("Nein", "0")
|
||||
query = "SELECT * FROM semesterapparat WHERE "
|
||||
for key, value in kwargs.items() if kwargs.items() is not None else {}:
|
||||
# print(key, value)
|
||||
# logger.debug(key, value)
|
||||
query += f"{key}='{value}' AND "
|
||||
# print(query)
|
||||
# logger.debug(query)
|
||||
# remove deletesemester part from normal query, as this will be added to the database upon deleting the apparat
|
||||
if "deletesemester" in kwargs.keys():
|
||||
query = query.replace(
|
||||
@@ -1128,7 +1126,7 @@ class Database:
|
||||
query = query.replace(
|
||||
f"endsemester='{kwargs['endsemester']}' AND ", "xyz"
|
||||
)
|
||||
# print("replaced")
|
||||
# logger.debug("replaced")
|
||||
query = query.replace(
|
||||
"xyz",
|
||||
f"(erstellsemester='{kwargs['endsemester']}' OR verlängerung_bis='{kwargs['endsemester']}') AND ",
|
||||
@@ -1143,9 +1141,9 @@ class Database:
|
||||
query = query[:-1]
|
||||
query = query.strip()
|
||||
|
||||
# print(query)
|
||||
# logger.debug(query)
|
||||
res = __query(query)
|
||||
# print(res)
|
||||
# logger.debug(res)
|
||||
return res
|
||||
|
||||
# Admin data
|
||||
@@ -1314,15 +1312,15 @@ class Database:
|
||||
"""
|
||||
return self.query_db("SELECT titel, fname,lname,mail,telnr,fullname FROM prof")
|
||||
|
||||
def restoreApparat(self, app_id: Union[str, int]):
|
||||
def restoreApparat(self, app_id: Union[str, int], app_name: str):
|
||||
"""restore an apparat from the database
|
||||
|
||||
Args:
|
||||
app_id (Union[str, int]): the id of the apparat
|
||||
"""
|
||||
return self.query_db(
|
||||
"UPDATE semesterapparat SET deletion_status=0, deleted_date=NULL WHERE appnr=?",
|
||||
(app_id,),
|
||||
"UPDATE semesterapparat SET deletion_status=0, deleted_date=NULL WHERE appnr=? and name=?",
|
||||
(app_id, app_name),
|
||||
)
|
||||
|
||||
# ELSA
|
||||
@@ -1433,7 +1431,7 @@ class Database:
|
||||
blob = self.query_db(
|
||||
"SELECT fileblob FROM elsa_files WHERE filename=?", (filename,), one=True
|
||||
)[0]
|
||||
# print(blob)
|
||||
# logger.debug(blob)
|
||||
tempdir = self.database.tempdir
|
||||
tempdir = tempdir.replace("~", str(Path.home()))
|
||||
tempdir_path = Path(tempdir)
|
||||
@@ -1443,7 +1441,7 @@ class Database:
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
file.write(blob)
|
||||
# print("file created")
|
||||
# logger.debug("file created")
|
||||
return file.name
|
||||
|
||||
def getElsaApparats(self) -> ELSA:
|
||||
|
||||
Reference in New Issue
Block a user