add iocn, mass mail, basic elsa functionality

This commit is contained in:
WorldTeacher
2024-05-21 13:30:12 +02:00
parent 04779a4b51
commit dc1f446017

View File

@@ -114,6 +114,13 @@ class Ui(Ui_Semesterapparat):
self.MainWindow = MainWindow self.MainWindow = MainWindow
# set the window title # set the window title
MainWindow.setWindowTitle("Semesterapparatsmanagement") MainWindow.setWindowTitle("Semesterapparatsmanagement")
icon = QtGui.QIcon()
icon.addPixmap(
QtGui.QPixmap("icons/logo.ico"),
QtGui.QIcon.Mode.Normal,
QtGui.QIcon.State.Off,
)
MainWindow.setWindowIcon(icon)
self.db = Database() self.db = Database()
# self.show() # self.show()
@@ -190,14 +197,15 @@ class Ui(Ui_Semesterapparat):
self.load_app.hide() self.load_app.hide()
print(f"user:{self.active_user}") print(f"user:{self.active_user}")
userrole = self.db.getRole(self.active_user) userrole = self.db.getRole(self.active_user)
# hide admin interface when non-admin is logged in
if userrole == "admin": if userrole == "admin":
self.tabWidget.setTabVisible(2, True)
self.tabWidget.setTabVisible(3, True)
else: else:
self.tabWidget.setTabVisible(2, False) self.tabWidget.setTabVisible(3, False)
# self.update_app_media_list() # self.update_app_media_list()
self.populate_prof_dropdown() self.populate_prof_dropdown()
self.populate_appfach_dropdown() self.populate_appfach_dropdown()
self.frame.setEnabled(False)
# if the focus is changed from the prof name dropdown, set the prof data if the prof exists in the database, otherwise show a message # if the focus is changed from the prof name dropdown, set the prof data if the prof exists in the database, otherwise show a message
self.drpdwn_prof_name.currentIndexChanged.connect(self.set_prof_data) self.drpdwn_prof_name.currentIndexChanged.connect(self.set_prof_data)
self.cancel_active_selection.clicked.connect(self.btn_cancel_active_selection) self.cancel_active_selection.clicked.connect(self.btn_cancel_active_selection)
@@ -210,10 +218,14 @@ class Ui(Ui_Semesterapparat):
self.app_fach.currentTextChanged.connect(self.validate_app_fach) self.app_fach.currentTextChanged.connect(self.validate_app_fach)
self.sem_year.textChanged.connect(self.validate_semester) self.sem_year.textChanged.connect(self.validate_semester)
self.check_eternal_app.stateChanged.connect(self.validate_semester) self.check_eternal_app.stateChanged.connect(self.validate_semester)
self.chkbx_show_del_media.setEnabled(False)
self.chkbx_show_del_media.stateChanged.connect(self.update_app_media_list) self.chkbx_show_del_media.stateChanged.connect(self.update_app_media_list)
self.label_info.hide()
self.progress_label.setText("Bitte warten...") self.progress_label.setText("Bitte warten...")
# Set visibility/enabled state of certain entries
self.chkbx_show_del_media.setEnabled(False)
self.label_info.hide()
self.frame.setEnabled(False)
self.line_2.hide() self.line_2.hide()
self.progress_label.hide() self.progress_label.hide()
self.message_frame.hide() self.message_frame.hide()
@@ -224,24 +236,20 @@ class Ui(Ui_Semesterapparat):
self.chkbx_show_del_media.hide() self.chkbx_show_del_media.hide()
self.groupBox_2.hide() self.groupBox_2.hide()
self.groupBox.hide() self.groupBox.hide()
self.btn_del_select_apparats.setEnabled(False)
self.check_deletable.stateChanged.connect(self.gridchange) self.check_deletable.stateChanged.connect(self.gridchange)
self.tableWidget.horizontalHeader().setSectionResizeMode( self.tableWidget.horizontalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Stretch QtWidgets.QHeaderView.ResizeMode.Stretch
) )
self.btn_del_select_apparats.setEnabled(False)
self.btn_del_select_apparats.clicked.connect(self.delete_selected_apparats) self.btn_del_select_apparats.clicked.connect(self.delete_selected_apparats)
self.statistics_table.doubleClicked.connect(self.display_detailed_data) self.statistics_table.doubleClicked.connect(self.display_detailed_data)
self.tabWidget_2.currentChanged.connect(self.tabW2_changed) self.tabWidget_2.currentChanged.connect(self.tabW2_changed)
self.tabWidget.currentChanged.connect(self.tabW1_changed) self.tabWidget.currentChanged.connect(self.tabW1_changed)
self.tableWidget.resizeColumnsToContents() self.tableWidget.resizeColumnsToContents()
self.tableWidget.resizeRowsToContents() self.tableWidget.resizeRowsToContents()
# set self.app_fach viable inputs to be
# self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()])
# self.app_fach.addItem("")
# self.app_fach.setCurrentText("")
# create a thread, that continually checks the validity of the inputs # create a thread, that continually checks the validity of the inputs
self.validate_thread = QThread() self.validate_thread = QThread()
self.validate_thread.started.connect(self.thread_check) self.validate_thread.started.connect(self.thread_check)
self.validate_thread.start() self.validate_thread.start()
@@ -286,7 +294,9 @@ class Ui(Ui_Semesterapparat):
self.tableWidget.customContextMenuRequested.connect( self.tableWidget.customContextMenuRequested.connect(
self.statistics_table_context_menu self.statistics_table_context_menu
) )
# statistic side buttons
self.btn_notify_for_deletion.clicked.connect(self.notify_for_deletion)
self.btn_notify_for_deletion.setEnabled(False)
# admin buttons # admin buttons
self.user_frame_addUser.clicked.connect(self.add_user) self.user_frame_addUser.clicked.connect(self.add_user)
self.pushButton.clicked.connect(self.delete_user) self.pushButton.clicked.connect(self.delete_user)
@@ -299,6 +309,40 @@ class Ui(Ui_Semesterapparat):
self.mail_thread = None self.mail_thread = None
self.autoGrabber = None self.autoGrabber = None
def notify_for_deletion(self):
# get all selected apparats
selected_apparats: list[dict] = []
for i in range(self.tableWidget.rowCount()):
data = {}
if self.tableWidget.cellWidget(i, 0).isChecked():
data["app_id"] = self.tableWidget.item(i, 2).text()
data["app_name"] = self.tableWidget.item(i, 1).text()
data["prof_name"] = self.tableWidget.item(i, 3).text()
selected_apparats.append(data)
# delete all selected apparats
ic(selected_apparats)
dialogs = []
for i in selected_apparats:
app_id = i["app_id"]
app_name = i["app_name"]
prof_name = i["prof_name"]
prof_mail = self.db.getProfData(prof_name)[0]
self.mail_thread = Mail_Dialog(
app_id=app_id,
app_name=app_name,
prof_name=prof_name,
prof_mail=prof_mail,
app_subject="",
default_mail="Information bezüglich der Auflösung des Semesterapparates",
)
dialogs.append(self.mail_thread)
for dialog in dialogs:
dialog.exec()
self.btn_notify_for_deletion.setEnabled(False)
def populate_appfach_dropdown(self): def populate_appfach_dropdown(self):
self.app_fach.clear() self.app_fach.clear()
self.app_fach.addItem("") self.app_fach.addItem("")
@@ -387,7 +431,7 @@ class Ui(Ui_Semesterapparat):
return return
userdata = AdminCommands().create_password(password) userdata = AdminCommands().create_password(password)
self.db.createUser( self.db.createUser(
username=username, user=username,
password=f"{userdata[1]}{userdata[0]}", password=f"{userdata[1]}{userdata[0]}",
salt=userdata[1], salt=userdata[1],
role=role, role=role,
@@ -779,6 +823,7 @@ class Ui(Ui_Semesterapparat):
"""Generate the statistics based on the selected filters.""" """Generate the statistics based on the selected filters."""
self.db_err_message.setText("") self.db_err_message.setText("")
self.btn_del_select_apparats.setEnabled(True) self.btn_del_select_apparats.setEnabled(True)
self.btn_notify_for_deletion.setEnabled(True)
params = { params = {
"appnr": ( "appnr": (
self.box_appnrs.currentText() self.box_appnrs.currentText()
@@ -891,6 +936,8 @@ class Ui(Ui_Semesterapparat):
self.prof_id_adis.setText(str(appdata.prof_adis_id)) self.prof_id_adis.setText(str(appdata.prof_adis_id))
self.apparat_id_adis.setText(str(appdata.apparat_adis_id)) self.apparat_id_adis.setText(str(appdata.apparat_adis_id))
self.frame.setEnabled(True) self.frame.setEnabled(True)
self.groupBox_2.hide()
self.groupBox.hide()
self.validateLoadedData() self.validateLoadedData()
def validateLoadedData(self): def validateLoadedData(self):
@@ -1105,6 +1152,9 @@ class Ui(Ui_Semesterapparat):
self.btn_apparat_save.hide() self.btn_apparat_save.hide()
self.btn_reserve.show() self.btn_reserve.show()
self.chkbx_show_del_media.show() self.chkbx_show_del_media.show()
self.groupBox_2.show()
self.groupBox.show()
self.drpdwn_app_nr.setDisabled(True) self.drpdwn_app_nr.setDisabled(True)
self.update_app_media_list() self.update_app_media_list()
self.update_documemt_list() self.update_documemt_list()
@@ -1131,6 +1181,8 @@ class Ui(Ui_Semesterapparat):
# child.clear() # child.clear()
def btn_create_new_apparat(self): def btn_create_new_apparat(self):
self.groupBox.show()
self.groupBox_2.show()
global valid_input global valid_input
# *create a new apparat # *create a new apparat
self.btn_apparat_save.show() if self.btn_apparat_save.isHidden() else None self.btn_apparat_save.show() if self.btn_apparat_save.isHidden() else None
@@ -1298,6 +1350,8 @@ class Ui(Ui_Semesterapparat):
self.chkbx_show_del_media.hide() self.chkbx_show_del_media.hide()
self.check_send_mail.hide() self.check_send_mail.hide()
self.btn_reserve.hide() self.btn_reserve.hide()
self.groupBox_2.hide()
self.groupBox.hide()
for child in self.frame.findChildren(QtWidgets.QLineEdit): for child in self.frame.findChildren(QtWidgets.QLineEdit):
child.clear() child.clear()
@@ -1655,6 +1709,8 @@ class Ui(Ui_Semesterapparat):
self.drpdwn_prof_name.clear() self.drpdwn_prof_name.clear()
self.tableWidget_apparat_media.setRowCount(0) self.tableWidget_apparat_media.setRowCount(0)
self.frame.setEnabled(False) self.frame.setEnabled(False)
self.groupBox_2.hide()
self.groupBox.hide()
self.check_send_mail.setChecked(False) self.check_send_mail.setChecked(False)
if not self.validate_fields(): if not self.validate_fields():