From 925a3c503333e3c8d625b8ee00c50ba4668149e2 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Thu, 8 Feb 2024 15:58:44 +0100 Subject: [PATCH] Add new method for generating semester by date --- src/logic/userInterface.py | 58 +++++++++++++++----------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/src/logic/userInterface.py b/src/logic/userInterface.py index 4d530c1..52bc59b 100644 --- a/src/logic/userInterface.py +++ b/src/logic/userInterface.py @@ -40,6 +40,7 @@ from src.ui import ( ) # from src.logic.webrequest import BibTextTransformer, WebRequest from src.backend.admin_console import AdminCommands +from src.backend.semester import generateSemesterByDate from src.backend.create_file import recreateFile from src.backend.delete_temp_contents import delete_temp_contents from src.logic.csvparser import csv_to_list @@ -267,6 +268,7 @@ class Ui(Ui_Semesterapparat): # create a thread, that continually checks the validity of the inputs self.grabbers = [] + self.threadeds = [] self.thread = QThread() self.validate_thread = QThread() self.validate_thread.started.connect(self.thread_check) @@ -525,13 +527,7 @@ class Ui(Ui_Semesterapparat): str: The current semester """ if today: - currentYear = QDate.currentDate().year() - currentYear = int(str(currentYear)[-2:]) - month = QDate.currentDate().month() - if month >= 4 and month <= 9: - return "SoSe " + str(currentYear) - else: - return f"WiSe {currentYear}/{currentYear+1}" + return generateSemesterByDate() currentYear = self.sem_year.text() currentYear = int(currentYear[-2:]) @@ -670,7 +666,7 @@ class Ui(Ui_Semesterapparat): ) self.box_fach.addItems(subject[1] for subject in self.db.getSubjects()) semester = self.db.getSemersters() - self.box_erstellsemester.addItems([sem[0] for sem in semester]) + self.box_erstellsemester.addItems(semester) self.statistics_table.setRowCount(0) #set data for table and graph in tab 2 tableWidget_3 @@ -1164,7 +1160,7 @@ class Ui(Ui_Semesterapparat): # worker.finished.connect(worker.deleteLater) grabber.start() - self.thread = thread + self.threadeds.append(thread) self.grabbers.append(grabber) # for book in data: @@ -1182,8 +1178,14 @@ class Ui(Ui_Semesterapparat): return def check_availability(self): - def _update_progress(state): - self.avail_status.setText( "{}/{}".format(state[0], state[1])) + self.threadeds.clear() + def _update_progress(current, all_titles): + self.avail_status.setText( "{}/{}".format(current, all_titles)) + self.btn_reserve.setStatusTip(f"Verfügbarkeit wird geprüft, bitte warten... {current}/{all_titles}") + def _hide_progress_label(): + self.label_20.hide() + self.avail_status.hide() + self.avail_status.setText("0/0") # get all links from the table # if no index in tableWidget_apparat_media is selected, check all if self.tableWidget_apparat_media.currentRow() == -1: @@ -1203,6 +1205,7 @@ class Ui(Ui_Semesterapparat): self.label_20.setText("Verfügbarkeit wird geprüft, bitte warten...") self.label_20.show() self.avail_status.setText(f"0/{items}") + self.avail_status.show() books = self.db.getBooks( self.active_apparat(), self.db.getProfId(self.drpdwn_prof_name.currentText()), @@ -1216,11 +1219,11 @@ class Ui(Ui_Semesterapparat): availcheck.moveToThread(thread) availcheck.finished.connect(thread.quit) availcheck.finished.connect(availcheck.deleteLater) - availcheck.finished.connect(self.hide_progress_label) availcheck.finished.connect(self.update_app_media_list) availcheck.updateProgress.connect(_update_progress) + availcheck.finished.connect(_hide_progress_label) availcheck.start() - self.thread = thread + self.threadeds.append(thread) self.grabbers.append(availcheck) def btn_cancel_active_selection(self): @@ -1503,7 +1506,7 @@ class Ui(Ui_Semesterapparat): # 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_type = self.dokument_list.item( self.dokument_list.currentRow(), 1 ).text() @@ -1515,6 +1518,8 @@ class Ui(Ui_Semesterapparat): ).text() if file_location == "Database": file = recreateFile(file_name,app_id,file_type,open=False) + else: + self.add_files() if file_type == "pdf": # Todo: implement parser here self.confirm_popup("PDF Dateien werden noch nicht unterstützt!") @@ -1595,24 +1600,6 @@ class Ui(Ui_Semesterapparat): appd.prof_mail = self.prof_mail.text() appd.app_fach = self.app_fach.currentText() appd.erstellsemester = self.generateSemester() - # curr_fach_alias = self.db.get_subjects_and_aliases() - # for fach in curr_fach_alias: - # if app_fach in fach: - # appd.app_fach = app_fach - # break - # else: - # #create a popup to ask for the correct subject - # dialog = QtWidgets.QDialog() - # popup = new_subject_ui() - # popup.setupUi(dialog) - # new_subject = popup.return_state() - # dialog.exec() - # if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: - # appd.app_fach = new_subject - # self.db.add_subject(new_subject) - # else: - # return - appd.deleted = 0 appd.prof_adis_id = self.prof_id_adis.text() appd.apparat_adis_id = self.apparat_id_adis.text() @@ -1621,8 +1608,8 @@ class Ui(Ui_Semesterapparat): if not self.validate_fields(): pass self.db.createApparat(appd) - if self.dokument_list.rowCount() > 0: - self.add_files() + # if self.dokument_list.rowCount() > 0: + self.add_files() appdata = self.db.getAllAparats() # merge self.appdata and appdata, remove duplicates self.apparats = list(set(self.apparats + appdata)) @@ -1943,7 +1930,7 @@ class Ui(Ui_Semesterapparat): print(state) if state == 1: self.db.deleteApparat( - selected_apparat_id, self.generateSemester(today=True) + selected_apparat_id, generateSemesterByDate() ) # delete the corresponding entry from self.apparats for apparat in self.apparats: @@ -1997,7 +1984,6 @@ def launch_gui(): # open a console window # console = "" print("admin") - # atexit.register(aui.thread.terminate) atexit.register(delete_temp_contents)