rebase codebase, delete trunk, move threads to backend

This commit is contained in:
2025-01-14 16:20:08 +01:00
parent fba652006f
commit 08cd18f3f1
106 changed files with 1604 additions and 1057 deletions

View File

@@ -28,6 +28,8 @@ from string import ascii_lowercase as lower, digits, punctuation
ascii_lowercase = lower + digits + punctuation
# get the line that called the function
class Database:
database = settings.database
@@ -673,9 +675,6 @@ class Database:
)[0]
return f"{title} " if title is not None else ""
def getSpecificProfData(self, prof_id: Union[str, int], fields: List[str]) -> tuple:
"""A customisable function to get specific data of a professor based on the id
@@ -729,8 +728,9 @@ class Database:
list[tuple]: a list containing all the professors in individual tuples
tuple: (id, titel, fname, lname, fullname, mail, telnr)
"""
profs = self.query_db("SELECT * FROM prof")
profs = self.query_db("SELECT * FROM prof")
return [Prof().from_tuple(prof) for prof in profs]
# Apparat
def getAllAparats(self, deleted=0) -> list[tuple]:
"""Get all the apparats in the database
@@ -865,6 +865,7 @@ class Database:
logger.debug(query)
self.query_db(query)
return None
def getApparatsByProf(self, prof_id: Union[str, int]) -> list[tuple]:
"""Get all apparats based on the professor id
@@ -1362,6 +1363,7 @@ class Database:
entries.append(elsa_id)
query = f"INSERT INTO elsa_media ({', '.join(headers)}) VALUES ({', '.join(['?' for i in range(len(headers))])})"
self.query_db(query, entries)
def getElsaMedia(self, elsa_id: int):
"""get all the media of an ELSA apparat
@@ -1468,7 +1470,8 @@ class Database:
return self.query_db(
"SELECT filename, filetyp FROM elsa_files WHERE elsa_id=?", (elsa_id,)
)
###
###
def createProf(self, profdata: Prof):
logger.debug(profdata)
@@ -1480,30 +1483,32 @@ class Database:
mail = profdata.mail
telnr = profdata.telnr
title = profdata.title
query = f"INSERT INTO prof (fname, lname, fullname, mail, telnr,titel) VALUES ('{fname}','{lname}','{fullname}','{mail}','{telnr}','{title}')"
logger.debug(query)
cursor.execute(query)
conn.commit()
conn.close()
return self.getProfId(profdata)
def getElsaProfId(self, profname):
query = f"SELECT id FROM elsa_prof WHERE fullname = '{profname}'"
data = self.query_db(query)
if data:
return data[0][0]
else: return None
else:
return None
def getElsaProfs(self)->list[str]:
def getElsaProfs(self) -> list[str]:
query = "SELECT fullname FROM elsa_prof"
data = self.query_db(query)
if data:
return [i[0] for i in data]
else: return []
def getProfId(self, profdata: dict|Prof):
else:
return []
def getProfId(self, profdata: dict | Prof):
"""Get the prof ID based on the profdata
Args:
@@ -1518,7 +1523,7 @@ class Database:
fullname = profdata.name()
else:
name = profdata["profname"]
if ","in name:
if "," in name:
fname = name.split(", ")[1].strip()
lname = name.split(", ")[0].strip()
fullname = f"{lname} {fname}"
@@ -1526,28 +1531,30 @@ class Database:
fullname = profdata["profname"]
query = f"SELECT id FROM prof WHERE fullname = '{fullname}'"
logger.debug(query)
cursor.execute(query)
result = cursor.fetchone()
if result:
result = cursor.fetchone()
if result:
return result[0]
else: return None
else:
return None
def getProfByName(self, fullname):
'''Get all Data of the prof based on fullname
"""Get all Data of the prof based on fullname
Args:
fullname (str): The full name of the prof
'''
"""
conn = self.connect()
cursor = conn.cursor()
query = f"SELECT * FROM prof WHERE fullname = '{fullname}'"
logger.debug(query)
result = cursor.execute(query).fetchone()
if result:
return Prof().from_tuple(result)
else: return Prof()
else:
return Prof()
def getProfIDByApparat(self, apprarat_id):
"""Get the prof id based on the semesterapparat id from the database
@@ -1606,4 +1613,5 @@ class Database:
data = self.query_db(query)
if data:
return data[0][0]
else: return None
else:
return None