rework prof data using dataclass, change database code, fix bugs

This commit is contained in:
WorldTeacher
2024-09-23 15:45:42 +02:00
parent e91a40695a
commit cd74214c17
10 changed files with 150 additions and 65 deletions

View File

@@ -19,6 +19,7 @@ from src import Icon
from src.backend import (
Database,
generateSemesterByDate,
recreateFile,
tempdelete,
)
@@ -295,6 +296,7 @@ class Ui(Ui_Semesterapparat):
self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()])
def open_documentation(self):
raise NotImplementedError("Documentation not implemented yet")
# open the documentation in the default browser
webbrowser.open("file:///" + os.path.abspath("docs/index.html"))
# documentation = documentationview.DocumentationViewer()
@@ -310,7 +312,7 @@ class Ui(Ui_Semesterapparat):
widget.deleteLater()
statistics = SearchStatisticPage()
statistics.apparat_open.connect(self.open_apparat)
statistics.reloadSignal.connect(self.reload)
statistics.refreshSignal.connect(self.update_apparat_list)
stats_layout.addWidget(statistics)
@@ -431,7 +433,7 @@ class Ui(Ui_Semesterapparat):
else self.sem_winter.text() + " " + self.sem_year.text()
)
appdata.prof_adis_id = self.prof_id_adis.text()
prof_id = self.db.getProfByName(appdata.profname)[0]
prof_id = self.db.getProfByName(appdata.prof_details.fullname).id
self.add_files(prof_id)
appdata.apparat_adis_id = self.apparat_id_adis.text()
@@ -443,6 +445,8 @@ class Ui(Ui_Semesterapparat):
self.chkbx_show_del_media.show()
self.cancel_active_selection.setEnabled(False)
self.add_medium.setEnabled(False)
#update apparat table
self.get_apparats()
def confirm_popup(self, message: str, title: str):
popup = popus_confirm(title=title)
@@ -538,6 +542,7 @@ class Ui(Ui_Semesterapparat):
valid_input = list(valid_input)
valid_input[index] = state
valid_input = tuple(valid_input)
def set_state(self):
# set state of semester and year
@@ -561,12 +566,13 @@ class Ui(Ui_Semesterapparat):
selected_prof = self.drpdwn_prof_name.currentText()
data = self.db.getProfData(selected_prof)
# ic(data)
prof_title = data[2]
prof_title = data.title
if prof_title == "None":
prof_title = "Kein Titel"
self.prof_title.setText(prof_title)
self.prof_tel_nr.setText(data[1])
self.prof_mail.setText(data[0])
self.prof_tel_nr.setText(data.telnr)
self.prof_mail.setText(data.mail)
self.app_name.setFocus()
def get_index_of_value(self, table_widget, value):
for i in range(table_widget.rowCount()):
@@ -614,7 +620,7 @@ class Ui(Ui_Semesterapparat):
app_id = self.active_apparat
prof_id = self.db.getProfByName(
self.drpdwn_prof_name.currentText().replace(",","")
)[0]
).id
files = self.db.getFiles(app_id, prof_id)
for file in files:
self.dokument_list.insertRow(0)
@@ -887,7 +893,7 @@ class Ui(Ui_Semesterapparat):
if columnname == "Link":
link = __openLink(item.text())
if link is not None:
webbrowser.open(link)
os.system("start " + link)
return
else:
pass
@@ -903,7 +909,7 @@ class Ui(Ui_Semesterapparat):
# add empty entry to dropdown and set it as current
self.drpdwn_prof_name.addItem("Kein Name")
for prof in profs:
self.drpdwn_prof_name.addItem(f"{prof[3]}, {prof[2]}")
self.drpdwn_prof_name.addItem(f"{prof.lastname}, {prof.firstname}")
def add_document(self):
# print("Add document")
@@ -1113,6 +1119,8 @@ class Ui(Ui_Semesterapparat):
# print("starting thread")
if prof_id is None:
prof_id = self.db.getProfId(self.profdata)
print("Prof ID is None", prof_id)
autoGrabber = BookGrabber(self.active_apparat)
autoGrabber.add_values(
mode="ARRAY", app_id=app_id, prof_id=prof_id, data=signatures
@@ -1188,8 +1196,7 @@ class Ui(Ui_Semesterapparat):
appd.deleted = 0
appd.prof_adis_id = self.prof_id_adis.text()
appd.apparat_adis_id = self.apparat_id_adis.text()
if not self.validate_fields():
pass
error = self.db.createApparat(appd)
if self.dokument_list.rowCount() > 0:
@@ -1260,6 +1267,7 @@ class Ui(Ui_Semesterapparat):
def update_apparat_list(self):
self.tableWidget_apparate.setRowCount(0)
for apparat in self.apparats:
self.insert_apparat_into_table(apparat)
@@ -1387,14 +1395,6 @@ class Ui(Ui_Semesterapparat):
self.reload()
def reload(self):
# create a new connection to the database, refresh table data and replace the old connection
# self.db = Database()
# self.apparats = self.db.getAllAparats(deleted=0)
# self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True)
# self.tableWidget_apparate.setRowCount(0)
# for apparat in self.apparats:
# self.insert_apparat_into_table(apparat)
# kill the process and restart the application
state = self.confirm_popup(
"Bitte das Programm neustarten, um Änderungen zu übernehemen",
"Einstellungen geändert",
@@ -1535,7 +1535,7 @@ class Ui(Ui_Semesterapparat):
# if pid == "":
# pid = profname
# get the row of the clicked cell
prof_id = self.db.getProfByName(pid)[0]
prof_id = self.db.getProfByName(pid).id
# if profname == "Name Kein":
# profname = pid
if self.app_name.text() != "":