fix some bugs, add mail template emit signal to update list

This commit is contained in:
2025-02-06 15:36:04 +01:00
parent 4d1fc94ffa
commit 709a342230
6 changed files with 472 additions and 679 deletions

View File

@@ -13,7 +13,7 @@ from PyQt6.QtCore import QThread
from PyQt6.QtGui import QRegularExpressionValidator
from src import Icon, logger
from src.backend import Database, BookGrabber, AvailChecker
from src.backend import Database, BookGrabber, AvailChecker, DocumentationThread
from src.backend.semester import Semester
from src.backend.create_file import recreateFile
from src.backend.delete_temp_contents import delete_temp_contents as tempdelete
@@ -79,7 +79,8 @@ class Ui(Ui_Semesterapparat):
self.add_medium.clicked.connect(self.btn_add_medium)
self.btn_copy_adis_command.clicked.connect(self.text_to_clipboard)
self.btn_reserve.clicked.connect(self.check_availability)
self.calendarWidget = MessageCalendar(self.frame_2)
self.create_document.clicked.connect(self.create_doc)
self.calendarWidget = MessageCalendar(self.calendar_frame)
self.calendarWidget.setGridVisible(True)
self.calendarWidget.setVerticalHeaderFormat(
QtWidgets.QCalendarWidget.VerticalHeaderFormat.NoVerticalHeader
@@ -100,7 +101,7 @@ class Ui(Ui_Semesterapparat):
# Actions
self.actionEinstellungen.triggered.connect(self.open_settings)
Icon("settings", self.actionEinstellungen)
self.actionDokumentation.triggered.connect(self.open_documentation)
self.actionDokumentation_lokal.triggered.connect(self.open_documentation)
Icon("offAction", self.actionBeenden)
self.actionBeenden.triggered.connect(self.quit)
self.actionAbout.triggered.connect(self.open_about)
@@ -184,9 +185,9 @@ class Ui(Ui_Semesterapparat):
self.validate_thread.started.connect(self.thread_check)
self.validate_thread.start()
self.add_medium.setEnabled(False)
self.docuthread = QThread()
self.docuthread.started.connect(self.create_doc)
self.create_document.clicked.connect(self.docuthread.start)
self.docu = DocumentationThread()
self.docu.start()
self.actionDokumentation_lokal.triggered.connect(self.open_documentation)
# get all current apparats and cache them in a list
self.apparats = self.get_apparats()
@@ -224,14 +225,21 @@ class Ui(Ui_Semesterapparat):
self.elsatab.setLayout(QtWidgets.QVBoxLayout())
self.search_statistics.setLayout(QtWidgets.QVBoxLayout())
# once inputSignal emits, check state
# add splitter
self.splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Vertical)
self.splitter.addWidget(self.calendar_frame)
self.splitter.addWidget(self.frame_creation_progress)
self.verticalLayout.removeWidget(self.calendar_frame)
self.verticalLayout.removeWidget(self.frame_creation_progress)
self.verticalLayout.addWidget(self.splitter)
self.steps.hide()
def create_doc(self):
result = self.confirm_popup(
"Mit dem Klick auf Okay wird eine Übersicht aller aktiven Semesterapparate erstellt und an den FollowME Drucker gesendet. Es kann bis zu 10 Minuten dauern, bis das Dokument im Drucker angezeigt wird",
"Dokument erstellen?",
"Mit dem Klick auf Okay wird eine Übersicht aller aktiven Semesterapparate erstellt und an den FollowME Drucker gesendet. Es kann bis zu 10 Minuten dauern, bis das document im Drucker angezeigt wird",
"document erstellen?",
)
if result == QtWidgets.QDialog.DialogCode.Accepted:
# print("Creating document")
@@ -321,11 +329,12 @@ 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()
# documentation.show()
logger.info("Opening Documentation")
webbrowser.open("http://localhost:8000")
def update_calendar(self, data):
self.calendarWidget.setMessages([data])
self.calendarWidget.updateCells()
def tabW1_changed(self):
if self.tabWidget.currentIndex() == 1: # Statistics
@@ -340,7 +349,7 @@ class Ui(Ui_Semesterapparat):
statistics = SearchStatisticPage()
statistics.apparat_open.connect(self.open_apparat)
statistics.refreshSignal.connect(self.update_apparat_list)
statistics.updateCalendar.connect(self.update_calendar)
stats_layout.addWidget(statistics)
# #print("searchpage")
@@ -618,7 +627,7 @@ class Ui(Ui_Semesterapparat):
self.sem_sommer.setEnabled(False)
self.sem_winter.setEnabled(False)
self.sem_year.setEnabled(False)
self.dokument_list.setRowCount(0)
self.document_list.setRowCount(0)
self.chkbx_show_del_media.setEnabled(True)
appdata = self.db.getApparatData(appnr, appname)
self.populate_frame(appdata)
@@ -628,22 +637,22 @@ class Ui(Ui_Semesterapparat):
self.drpdwn_app_nr.setDisabled(True)
self.update_app_media_list()
self.update_documemt_list()
self.update_document_list()
return True
def update_documemt_list(self):
def update_document_list(self):
app_id = self.active_apparat
prof_id = self.db.getProfByName(
self.drpdwn_prof_name.currentText().replace(",", "")
).id
files = self.db.getFiles(app_id, prof_id)
for file in files:
self.dokument_list.insertRow(0)
self.dokument_list.setItem(0, 0, QtWidgets.QTableWidgetItem(file[0]))
self.dokument_list.setItem(0, 1, QtWidgets.QTableWidgetItem(file[1]))
self.dokument_list.setItem(0, 2, QtWidgets.QTableWidgetItem(""))
self.dokument_list.setItem(0, 3, QtWidgets.QTableWidgetItem("Database"))
self.dokument_list.item(0, 0).setToolTip(file[0])
self.document_list.insertRow(0)
self.document_list.setItem(0, 0, QtWidgets.QTableWidgetItem(file[0]))
self.document_list.setItem(0, 1, QtWidgets.QTableWidgetItem(file[1]))
self.document_list.setItem(0, 2, QtWidgets.QTableWidgetItem(""))
self.document_list.setItem(0, 3, QtWidgets.QTableWidgetItem("Database"))
self.document_list.item(0, 0).setToolTip(file[0])
def btn_create_new_apparat(self):
global valid_input
@@ -652,9 +661,9 @@ class Ui(Ui_Semesterapparat):
child.show()
# *create a new apparat
self.btn_apparat_save.show() if self.btn_apparat_save.isHidden() else None
# clear dokumemt_list
# clear document_list
self.__clear_fields()
self.dokument_list.setRowCount(0)
self.document_list.setRowCount(0)
self.cancel_active_selection.setEnabled(True)
self.app_group_box.setEnabled(True)
self.add_medium.setEnabled(True)
@@ -749,7 +758,6 @@ class Ui(Ui_Semesterapparat):
return
def check_availability(self):
# self.threadeds.clear()
def _update_progress(current, all_titles):
self.avail_status.setText("{}/{}".format(current, all_titles))
@@ -798,14 +806,13 @@ class Ui(Ui_Semesterapparat):
self.availChecker.start()
# kill availcheck after completion
# self.threadeds.append(thread)
# self.grabbers.append(availcheck)
def btn_cancel_active_selection(self):
self.steps.hide()
# clear the rows of the table
self.tableWidget_apparat_media.setRowCount(0)
self.dokument_list.setRowCount(0)
self.document_list.setRowCount(0)
self.app_group_box.setEnabled(False)
self.app_fach.setCurrentText("")
self.chkbx_show_del_media.hide()
@@ -945,30 +952,30 @@ class Ui(Ui_Semesterapparat):
# #print(file)
filename = file.split("/")[-1]
filetype = filename.split(".")[-1]
self.dokument_list.insertRow(0)
self.dokument_list.setItem(0, 0, QtWidgets.QTableWidgetItem(filename))
self.dokument_list.setItem(0, 1, QtWidgets.QTableWidgetItem(filetype))
self.dokument_list.setItem(0, 2, QtWidgets.QTableWidgetItem("*"))
self.dokument_list.setItem(0, 3, QtWidgets.QTableWidgetItem(file))
self.document_list.insertRow(0)
self.document_list.setItem(0, 0, QtWidgets.QTableWidgetItem(filename))
self.document_list.setItem(0, 1, QtWidgets.QTableWidgetItem(filetype))
self.document_list.setItem(0, 2, QtWidgets.QTableWidgetItem("*"))
self.document_list.setItem(0, 3, QtWidgets.QTableWidgetItem(file))
# set tooltip of row 3 to the file path for each row
self.dokument_list.item(0, 3).setToolTip(file)
self.dokument_list.item(0, 0).setToolTip(filename)
self.document_list.item(0, 3).setToolTip(file)
self.document_list.item(0, 0).setToolTip(filename)
def open_document(self):
_selected_doc_name = ""
_selected_doc_filetype = ""
try:
_selected_doc_name = self.dokument_list.item(
self.dokument_list.currentRow(), 0
_selected_doc_name = self.document_list.item(
self.document_list.currentRow(), 0
).text()
_selected_doc_location = self.dokument_list.item(
self.dokument_list.currentRow(), 3
_selected_doc_location = self.document_list.item(
self.document_list.currentRow(), 3
).text()
_selected_doc_filetype = self.dokument_list.item(
self.dokument_list.currentRow(), 1
_selected_doc_filetype = self.document_list.item(
self.document_list.currentRow(), 1
).text()
except AttributeError:
self.confirm_popup("Bitte erst ein Dokument auswählen!", title="Fehler")
self.confirm_popup("Bitte erst ein document auswählen!", title="Fehler")
return
if not _selected_doc_location == "Database":
path = Path(_selected_doc_location + "/" + _selected_doc_name)
@@ -1009,24 +1016,24 @@ class Ui(Ui_Semesterapparat):
# get
# if files are in the table, and are selected, check for books in the file
if self.dokument_list.rowCount() == 0:
if self.document_list.rowCount() == 0:
return
else:
# if file is selected, check for books in the file
if self.dokument_list.currentRow() != -1:
if self.document_list.currentRow() != -1:
# #print("File selected")
file = self.dokument_list.item(
self.dokument_list.currentRow(), 3
file = self.document_list.item(
self.document_list.currentRow(), 3
).text()
file_type = self.dokument_list.item(
self.dokument_list.currentRow(), 1
file_type = self.document_list.item(
self.document_list.currentRow(), 1
).text()
file_location = self.dokument_list.item(
self.dokument_list.currentRow(), 3
file_location = self.document_list.item(
self.document_list.currentRow(), 3
).text()
file_name = self.dokument_list.item(
self.dokument_list.currentRow(), 0
file_name = self.document_list.item(
self.document_list.currentRow(), 0
).text()
if file_location == "Database":
# create a temporaty file to use, delete it after use
@@ -1041,7 +1048,7 @@ class Ui(Ui_Semesterapparat):
if file_type == "pdf":
# Todo: implement parser here
self.confirm_popup(
"PDF Dateien werden nochnicht unterstützt!", title="Fehler"
"PDF Dateien werden noch nicht unterstützt!", title="Fehler"
)
return
if file_type == "csv":
@@ -1096,7 +1103,7 @@ class Ui(Ui_Semesterapparat):
if not self.btn_save_apparat(False):
return
created = True
if self.dokument_list.rowCount() == 0:
if self.document_list.rowCount() == 0:
# #print("No file selected")
self.tableWidget_apparate.setEnabled(True)
self.tableWidget_apparate.setToolTip("")
@@ -1104,16 +1111,16 @@ class Ui(Ui_Semesterapparat):
else:
# if file is selected, check for books in the file
# #print("File selected")
file = self.dokument_list.item(self.dokument_list.currentRow(), 3).text()
file = self.document_list.item(self.document_list.currentRow(), 3).text()
file_type = self.dokument_list.item(
self.dokument_list.currentRow(), 1
file_type = self.document_list.item(
self.document_list.currentRow(), 1
).text()
file_location = self.dokument_list.item(
self.dokument_list.currentRow(), 3
file_location = self.document_list.item(
self.document_list.currentRow(), 3
).text()
file_name = self.dokument_list.item(
self.dokument_list.currentRow(), 0
file_name = self.document_list.item(
self.document_list.currentRow(), 0
).text()
if file_location == "Database":
file = recreateFile(file_name, app_id, file_type, open=False)
@@ -1182,7 +1189,7 @@ class Ui(Ui_Semesterapparat):
self.app_fach.setCurrentText("")
self.app_name.clear()
self.sem_year.clear()
self.dokument_list.setRowCount(0)
self.document_list.setRowCount(0)
self.sem_winter.setChecked(False)
self.sem_sommer.setChecked(False)
self.check_eternal_app.setChecked(False)
@@ -1224,7 +1231,7 @@ class Ui(Ui_Semesterapparat):
if error:
self.confirm_popup(error.__str__(), title="Fehler")
return False
if self.dokument_list.rowCount() > 0:
if self.document_list.rowCount() > 0:
self.add_files()
if error is not None:
self.confirm_popup(error.__str__(), title="Fehler")
@@ -1268,16 +1275,16 @@ class Ui(Ui_Semesterapparat):
def add_files(self, prof_id=None):
files = []
for i in range(self.dokument_list.rowCount()):
for i in range(self.document_list.rowCount()):
files.append(
{
"name": self.dokument_list.item(i, 0).text(),
"type": self.dokument_list.item(i, 1).text(),
"date": self.dokument_list.item(i, 2).text(),
"path": self.dokument_list.item(i, 3).text(),
"name": self.document_list.item(i, 0).text(),
"type": self.document_list.item(i, 1).text(),
"date": self.document_list.item(i, 2).text(),
"path": self.document_list.item(i, 3).text(),
}
)
self.dokument_list.item(i, 2).setText("")
self.document_list.item(i, 2).setText("")
self.db.insertFile(
files,
@@ -1339,22 +1346,22 @@ class Ui(Ui_Semesterapparat):
remind_action = menu.addAction("Erinnerung")
menu.addAction(extend_action)
menu.addActions([contact_action, delete_action, remind_action])
extend_action.triggered.connect(self.extend_apparat)
remind_action.triggered.connect(self.reminder)
# convert point to row and column
row = self.tableWidget_apparate.rowAt(position.y())
column = self.tableWidget_apparate.columnAt(position.x())
pos = (str(row), str(column))
if len(self.tableWidget_apparate.selectedItems()) == 0:
return
pid = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 2)
app_id = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 0)
logger.debug(pos, pid)
extend_action.triggered.connect(self.extend_apparat)
app_id = self.tableWidget_apparate.item(row, 0).text()
pid = self.db.getProfIDByApparat(app_id)
logger.debug(app_id, pid)
delete_action.triggered.connect(lambda: self.delete_apparat(pos))
# pass pos to contact_prof
contact_action.triggered.connect(
lambda: self.contact_prof(pid=pid, apparat=app_id)
)
remind_action.triggered.connect(self.reminder)
menu.exec(self.tableWidget_apparate.mapToGlobal(position))
def reminder(self):
@@ -1371,11 +1378,10 @@ class Ui(Ui_Semesterapparat):
self.active_user,
self.active_apparat if self.active_apparat != "" else appnr,
)
self.calendarWidget.setMessages([data])
self.calendarWidget.updateCells()
self.update_calendar(data)
# self.db.update_bookdata(data, book_id)
# self.db.update_bookdata(data)
logger.info("Commited message to database")
logger.info("committed message to database")
# self.update_app_media_list()
def get_reminders(self):
@@ -1524,7 +1530,7 @@ class Ui(Ui_Semesterapparat):
signature = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1
).text()
medium = self.db.getBookBasedOnSignature(
self.db.getBookBasedOnSignature(
self.drpdwn_app_nr.currentText(),
signature=signature,
prof_id=self.db.getProfId(self.profdata),
@@ -1630,13 +1636,12 @@ class Ui(Ui_Semesterapparat):
else:
return
def __get_table_data_field(self, table, row, column):
logger.debug(row, column)
row = int(row)
return table.item(row, column).text()
def __contact_dialog(self, apparat, location: tuple | str, mail=None, pid=""):
logger.debug(location, pid, apparat)
logger.debug(
"Got these values apparat: {}, location: {}, mail: {}, pid: {}".format(
apparat, location, mail, pid
)
)
active_apparat_id = (
self.drpdwn_app_nr.currentText() if apparat is None else apparat
@@ -1644,15 +1649,10 @@ class Ui(Ui_Semesterapparat):
if not active_apparat_id:
# get column 0 of the selected row
pass
# #print(active_apparat_id)
# profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ")
# if profname != [""]:
# profname = f"{profname[1]} {profname[0]}"
# if pid == "":
# pid = profname
# get the row of the clicked cell
prof_id = self.db.getProfByName(pid).id
if isinstance(pid, str):
prof_id = self.db.getProfByName(pid).id
else:
prof_id = pid
# if profname == "Name Kein":
# profname = pid
if self.app_name.text() != "":
@@ -1664,16 +1664,11 @@ class Ui(Ui_Semesterapparat):
else:
app_subject = self.db.getApparatData(active_apparat_id, app_name)
app_subject = app_subject.apparat.subject
# profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}"
# #print(pid)
if prof_id:
pmail = self.db.getSpecificProfData(prof_id, ["mail"])
prof_name = self.db.getSpecificProfData(prof_id, ["fullname"])
else:
pmail = self.prof_mail.text()
# #print(prof_name)
# create a new thread to show the mail interface and send the mail
# #print("showing mail dialog")
self.mail_thread = Mail_Dialog(
app_id=active_apparat_id,
prof_name=prof_name,
@@ -1703,9 +1698,11 @@ class Ui(Ui_Semesterapparat):
message = f"Soll der Apparat {selected_apparat_id} wirklich gelöscht werden?"
state = self.confirm_popup(message, title="Löschen?")
# #print(state)
pid = self.__get_table_data_field(self.tableWidget_apparate, position[0], 2)
logger.info("Result state: {}", state)
if state == 1:
self.db.deleteApparat(selected_apparat_id)
logger.debug("Deleting apparat {}", selected_apparat_id)
pid = self.db.getProfIDByApparat(selected_apparat_id)
self.db.deleteApparat(selected_apparat_id, Semester().value)
# delete the corresponding entry from self.apparats
for apparat in self.apparats:
if apparat[4] == int(selected_apparat_id):