update ui related files & functions

This commit is contained in:
WorldTeacher
2024-01-31 15:31:25 +01:00
parent 4ff37d9452
commit c03865dcbd
5 changed files with 259 additions and 205 deletions

View File

@@ -7,17 +7,16 @@ import sys
import tempfile import tempfile
import time import time
from pathlib import Path from pathlib import Path
import webbrowser
from natsort import natsorted from natsort import natsorted
from omegaconf import OmegaConf from omegaconf import OmegaConf
from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import QDate, QThread, pyqtSignal from PyQt6.QtCore import QDate, QThread, pyqtSignal
from PyQt6.QtGui import QColor, QRegularExpressionValidator from PyQt6.QtGui import QColor, QRegularExpressionValidator
from src.logic import c_sort from src.logic import c_sort
from src.backend.database import Database from src.backend.database import Database
from src.logic.constants import APP_NRS, PROF_TITLES from src.logic.constants import APP_NRS, PROF_TITLES
from src.logic.dataclass import ApparatData, BookData, MailData from src.logic.dataclass import ApparatData, BookData, MailData,Subjects
from src.logic.log import MyLogger from src.logic.log import MyLogger
from src.logic.threads import BookGrabber,AvailChecker from src.logic.threads import BookGrabber,AvailChecker
from src.ui import ( from src.ui import (
@@ -121,6 +120,7 @@ class MessageCalendar(QtWidgets.QCalendarWidget):
) )
class Ui(Ui_Semesterapparat): class Ui(Ui_Semesterapparat):
# use the Ui_MainWindow class from mainwindow.py # use the Ui_MainWindow class from mainwindow.py
def __init__(self, MainWindow, username: str) -> None: def __init__(self, MainWindow, username: str) -> None:
@@ -158,6 +158,10 @@ class Ui(Ui_Semesterapparat):
) )
self.calendarWidget.setObjectName("MessageCalendar") self.calendarWidget.setObjectName("MessageCalendar")
self.calendarWidget.clicked.connect(self.open_reminder) self.calendarWidget.clicked.connect(self.open_reminder)
#assign a context menu to the calendar
self.calendarWidget.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.calendarWidget.customContextMenuRequested.connect(self.calendar_context_menu)
self.tableWidget_apparat_media.horizontalHeader().setSectionResizeMode( self.tableWidget_apparat_media.horizontalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Stretch QtWidgets.QHeaderView.ResizeMode.Stretch
) )
@@ -214,13 +218,14 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparate.doubleClicked.connect(self.load_app_data) self.tableWidget_apparate.doubleClicked.connect(self.load_app_data)
self.load_app.hide() self.load_app.hide()
print(f"user:{self.active_user}") print(f"user:{self.active_user}")
userrole = self.db.get_role(self.active_user) userrole = self.db.getRole(self.active_user)
if userrole == "admin": if userrole == "admin":
self.tabWidget.setTabVisible(2, True) self.tabWidget.setTabVisible(2, True)
else: else:
self.tabWidget.setTabVisible(2, False) self.tabWidget.setTabVisible(2, False)
# self.update_app_media_list() # self.update_app_media_list()
self.populate_prof_dropdown() self.populate_prof_dropdown()
self.populate_appfach_dropdown()
self.frame.setEnabled(False) 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)
@@ -263,8 +268,7 @@ class Ui(Ui_Semesterapparat):
self.validate_thread.start() self.validate_thread.start()
# get all current apparats and cache them in a list # get all current apparats and cache them in a list
self.apparats = self.db.get_all_apparts(deleted=0) self.apparats = self.db.getAllAparats(deleted=0)
print(self.apparats)
self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True)
for apparat in self.apparats: for apparat in self.apparats:
@@ -297,6 +301,11 @@ class Ui(Ui_Semesterapparat):
self.update_user.clicked.connect(self.update_user_data) self.update_user.clicked.connect(self.update_user_data)
self.update_faculty_member.clicked.connect(self.edit_faculty_member_action) self.update_faculty_member.clicked.connect(self.edit_faculty_member_action)
def populate_appfach_dropdown(self):
self.app_fach.clear()
self.app_fach.addItem("")
self.app_fach.setCurrentText("")
self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()])
def tabW1_changed(self): def tabW1_changed(self):
if self.tabWidget.currentIndex() == 1: if self.tabWidget.currentIndex() == 1:
@@ -315,15 +324,16 @@ class Ui(Ui_Semesterapparat):
} }
params = {key: value for key, value in params.items() if value is not None} params = {key: value for key, value in params.items() if value is not None}
ic(params) ic(params)
retdata = self.db.search_book(params) retdata = self.db.searchBook(params)
if retdata == None:
return
for book in retdata: for book in retdata:
ic(book)
self.book_search_result.insertRow(0) self.book_search_result.insertRow(0)
self.book_search_result.setItem(0,0,QtWidgets.QTableWidgetItem(book[0].title)) self.book_search_result.setItem(0,0,QtWidgets.QTableWidgetItem(book[0].title))
self.book_search_result.setItem(0,1,QtWidgets.QTableWidgetItem(book[0].signature)) self.book_search_result.setItem(0,1,QtWidgets.QTableWidgetItem(book[0].signature))
print(book[1]) print(book[1])
self.book_search_result.setItem(0,2,QtWidgets.QTableWidgetItem(self.db.get_apparats_name(book[1],book[2]))) self.book_search_result.setItem(0,2,QtWidgets.QTableWidgetItem(self.db.getApparatName(book[1],book[2])))
def edit_faculty_member_set_data(self): def edit_faculty_member_set_data(self):
@@ -332,7 +342,7 @@ class Ui(Ui_Semesterapparat):
fullname = name.replace(",","") fullname = name.replace(",","")
print(fullname,name) print(fullname,name)
#get the data for the selected member #get the data for the selected member
data = self.db.faculty_data(fullname) data = self.db.getProfByName(fullname)
#set the data #set the data
print(data) print(data)
if data == None: if data == None:
@@ -358,12 +368,12 @@ class Ui(Ui_Semesterapparat):
username = self.user_create_frame_username.text() username = self.user_create_frame_username.text()
password = self.user_create_frame_password.text() password = self.user_create_frame_password.text()
role = self.user_frame_userrole.currentText() role = self.user_frame_userrole.currentText()
if self.db.check_username(username): if self.db.checkUsername(username):
ic("username already exists") ic("username already exists")
# self.user_create_frame_error.setText("Der Nutzername ist bereits vergeben")#TODO: implement error message # self.user_create_frame_error.setText("Der Nutzername ist bereits vergeben")#TODO: implement error message
return return
userdata = AdminCommands().create_password(password) userdata = AdminCommands().create_password(password)
self.db.create_user(username=username, password=f"{userdata[1]}{userdata[0]}", salt=userdata[1], role=role) self.db.createUser(username=username, password=f"{userdata[1]}{userdata[0]}", salt=userdata[1], role=role)
self.user_create_frame_username.clear() self.user_create_frame_username.clear()
self.user_create_frame_password.clear() self.user_create_frame_password.clear()
self.user_frame_userrole.setCurrentText("") self.user_frame_userrole.setCurrentText("")
@@ -372,7 +382,7 @@ class Ui(Ui_Semesterapparat):
def delete_user(self): def delete_user(self):
if self.user_delete_confirm.isChecked(): if self.user_delete_confirm.isChecked():
username = self.user_delete_frame_user_select.currentText() username = self.user_delete_frame_user_select.currentText()
self.db.delete_user(username) self.db.deleteUser(username)
self.user_delete_frame_user_select.removeItem(self.user_delete_frame_user_select.currentIndex()) self.user_delete_frame_user_select.removeItem(self.user_delete_frame_user_select.currentIndex())
self.user_delete_confirm.setChecked(False) self.user_delete_confirm.setChecked(False)
else: else:
@@ -392,7 +402,7 @@ class Ui(Ui_Semesterapparat):
} }
data = {key: value for key, value in data.items() if value is not None} data = {key: value for key, value in data.items() if value is not None}
print(data) print(data)
self.db.update_user(username=username,data = data) self.db.updateUser(username=username,data = data)
self.user_edit_frame_user_select.setCurrentText("") self.user_edit_frame_user_select.setCurrentText("")
self.user_edit_frame_new_password.clear() self.user_edit_frame_new_password.clear()
self.user_edit_frame_role_select.setCurrentText("") self.user_edit_frame_role_select.setCurrentText("")
@@ -408,9 +418,9 @@ class Ui(Ui_Semesterapparat):
if fname != "" and lname != "": if fname != "" and lname != "":
return f"{lname} {fname}" return f"{lname} {fname}"
#get the data and use new value if it is not none and does not mach the old value #get the data and use new value if it is not none and does not mach the old value
if self.edit_faculty_member_select_member.currentText(""): if self.edit_faculty_member_select_member.currentText() =="":
return return
olddata = self.db.get_faculty_members(self.edit_faculty_member_select_member.currentText()) olddata = self.db.getFacultyMember(self.edit_faculty_member_select_member.currentText())
data = olddata[0] data = olddata[0]
oldlname = data[2] oldlname = data[2]
@@ -432,7 +442,7 @@ class Ui(Ui_Semesterapparat):
"telnr":telnr, "telnr":telnr,
} }
new_data = {key: value for key, value in new_data.items() if value != ""} new_data = {key: value for key, value in new_data.items() if value != ""}
self.db.update_faculty_member(data = new_data,oldlname=oldlname,oldfname=oldfname) self.db.updateFacultyMember(data = new_data,oldlname=oldlname,oldfname=oldfname)
self.add_faculty_member_data() self.add_faculty_member_data()
self.edit_faculty_member_new_title.setCurrentText("") self.edit_faculty_member_new_title.setCurrentText("")
self.edit_faculty_member_new_surname.clear() self.edit_faculty_member_new_surname.clear()
@@ -448,11 +458,11 @@ class Ui(Ui_Semesterapparat):
def admin_action_changed(self): def admin_action_changed(self):
action = self.select_action_box.currentText() action = self.select_action_box.currentText()
roles = self.db.get_roles() roles = self.db.getRoles()
roles = [role[0] for role in roles] roles = [role[0] for role in roles]
#remove duplicates #remove duplicates
roles = list(dict.fromkeys(roles)) roles = list(dict.fromkeys(roles))
users = self.db.get_users() users = self.db.getUsers()
users = [user[2] for user in users] users = [user[2] for user in users]
users.remove(self.active_user) users.remove(self.active_user)
if "admin" in users: if "admin" in users:
@@ -485,7 +495,7 @@ class Ui(Ui_Semesterapparat):
return return
def add_faculty_member_data(self): def add_faculty_member_data(self):
faculty_members = self.db.get_faculty_members() faculty_members = self.db.getFacultyMembers()
names = [f"{member[5]}" for member in faculty_members] names = [f"{member[5]}" for member in faculty_members]
self.edit_faculty_member_select_member.clear() self.edit_faculty_member_select_member.clear()
self.edit_faculty_member_select_member.addItems(names) self.edit_faculty_member_select_member.addItems(names)
@@ -535,7 +545,7 @@ class Ui(Ui_Semesterapparat):
self.statistics_table.currentRow(), 0 self.statistics_table.currentRow(), 0
).text() ).text()
# get all apparats from the selected semester # get all apparats from the selected semester
data = self.db.apparats_by_semester(selected_semester) data = self.db.getApparatsBySemester(selected_semester)
# replace keys for german names # replace keys for german names
# split to two lists # split to two lists
created = {"Erstellt": data["created"]} created = {"Erstellt": data["created"]}
@@ -566,8 +576,8 @@ class Ui(Ui_Semesterapparat):
print(apparat) print(apparat)
#person selected case - open all apparats from this person in the tableWidget #person selected case - open all apparats from this person in the tableWidget
self.tableWidget.setRowCount(0) self.tableWidget.setRowCount(0)
prof_id = self.db.get_prof_id(apparat.split("(")[0].strip()) prof_id = self.db.getProfId(apparat.split("(")[0].strip())
apparats = self.db.get_apparats_by_prof(prof_id) apparats = self.db.getApparatsByProf(prof_id)
for app in apparats: for app in apparats:
print(app) print(app)
#set the items 0 = clickable checkbox, 1 = appname, 2 = profname, 3 = fach #set the items 0 = clickable checkbox, 1 = appname, 2 = profname, 3 = fach
@@ -645,21 +655,21 @@ class Ui(Ui_Semesterapparat):
self.box_dauerapp.addItems(["Ja", "Nein", ""]) self.box_dauerapp.addItems(["Ja", "Nein", ""])
self.box_dauerapp.setCurrentText("") self.box_dauerapp.setCurrentText("")
#add custom vaules #add custom vaules
appnrs = self.db.get_apparat_nrs() appnrs = self.db.getUnavailableApparatNumbers()
apparats = natsorted(appnrs) apparats = natsorted(appnrs)
apparats = [str(apparat) for apparat in apparats] apparats = [str(apparat) for apparat in apparats]
self.box_appnrs.addItems(apparats) self.box_appnrs.addItems(apparats)
persons = self.db.get_profs() persons = self.db.getProfs()
self.box_person.addItems( self.box_person.addItems(
[f"{person[3]}, {person[2]}" for person in persons] [f"{person[3]}, {person[2]}" for person in persons]
) )
self.box_fach.addItems(subject[1] for subject in self.db.get_subjects()) self.box_fach.addItems(subject[1] for subject in self.db.getSubjects())
semester = self.db.get_semester() semester = self.db.getSemersters()
self.box_erstellsemester.addItems([sem[0] for sem in semester]) self.box_erstellsemester.addItems([sem[0] for sem in semester])
self.statistics_table.setRowCount(0) self.statistics_table.setRowCount(0)
#set data for table and graph in tab 2 tableWidget_3 #set data for table and graph in tab 2 tableWidget_3
data = self.db.get_app_count_by_semester() data = self.db.getApparatCountBySemester()
data = c_sort.custom_sort(data) data = c_sort.custom_sort(data)
# self.tabWidget_3.clear() # self.tabWidget_3.clear()
self.tabWidget_3.removeTab(1) self.tabWidget_3.removeTab(1)
@@ -716,7 +726,7 @@ class Ui(Ui_Semesterapparat):
# delete all selected apparats # delete all selected apparats
print(selected_apparats) print(selected_apparats)
for apparat in selected_apparats: for apparat in selected_apparats:
self.db.delete_apparat(apparat, self.generateSemester(today=True)) self.db.deleteApparat(apparat, self.generateSemester(today=True))
# refresh the table # refresh the table
self.tab_changed() self.tab_changed()
self.btn_del_select_apparats.setEnabled(False) self.btn_del_select_apparats.setEnabled(False)
@@ -729,7 +739,7 @@ class Ui(Ui_Semesterapparat):
"appnr": self.box_appnrs.currentText() "appnr": self.box_appnrs.currentText()
if self.box_appnrs.currentText() != "" if self.box_appnrs.currentText() != ""
else None, else None,
"prof_id": self.db.get_prof_id(self.box_person.currentText()) "prof_id": self.db.getProfId(self.box_person.currentText())
if self.box_person.currentText() != "" if self.box_person.currentText() != ""
else None, else None,
"fach": self.box_fach.currentText() "fach": self.box_fach.currentText()
@@ -788,13 +798,23 @@ class Ui(Ui_Semesterapparat):
def populate_frame(self, appdata: ApparatData): def populate_frame(self, appdata: ApparatData):
# populate the frame with the data from the database # populate the frame with the data from the database
ic(appdata)
self.drpdwn_app_nr.setCurrentText(str(appdata.appnr)) self.drpdwn_app_nr.setCurrentText(str(appdata.appnr))
self.drpdwn_prof_title.setCurrentText(appdata.prof_title) self.prof_title.setText(appdata.prof_title)
self.drpdwn_prof_name.setCurrentText(appdata.profname) prof_name = appdata.profname.split(" ")
if len(prof_name) > 2:
fname = " ".join(prof_name[1:])
lname = prof_name[0]
prof_name = f"{lname}, {fname}"
else:
prof_name = ", ".join(prof_name)
self.drpdwn_prof_name.setCurrentText(prof_name)
self.prof_mail.setText(appdata.prof_mail) self.prof_mail.setText(appdata.prof_mail)
self.prof_tel_nr.setText(appdata.prof_tel) self.prof_tel_nr.setText(appdata.prof_tel)
self.app_name.setText(appdata.appname) self.app_name.setText(appdata.appname)
print("changing dropdown app_fach from '' to ", appdata.app_fach)
self.app_fach.setCurrentText(appdata.app_fach) self.app_fach.setCurrentText(appdata.app_fach)
print("changed dropdown app_fach to ", self.app_fach.currentText())
if appdata.semester is not None: if appdata.semester is not None:
self.sem_sommer.setChecked( self.sem_sommer.setChecked(
True if appdata.semester.split(" ")[0] == "SoSe" else False True if appdata.semester.split(" ")[0] == "SoSe" else False
@@ -815,16 +835,25 @@ 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.validateLoadedData()
def validateLoadedData(self):
self.validate_prof_mail()
self.validate_prof_name()
self.validate_prof_tel()
self.validate_app_name()
self.validate_app_fach()
self.validate_semester()
def update_apparat(self): def update_apparat(self):
appdata = ApparatData() appdata = ApparatData()
appdata.app_fach = self.app_fach.text() appdata.app_fach = self.app_fach.currentText()
appdata.appname = self.app_name.text() appdata.appname = self.app_name.text()
appdata.appnr = self.active_apparat() appdata.appnr = self.active_apparat()
appdata.dauerapp = self.check_eternal_app.isChecked() appdata.dauerapp = self.check_eternal_app.isChecked()
appdata.prof_mail = self.prof_mail.text() appdata.prof_mail = self.prof_mail.text()
appdata.prof_tel = self.prof_tel_nr.text() appdata.prof_tel = self.prof_tel_nr.text()
appdata.prof_title = self.drpdwn_prof_title.currentText() appdata.prof_title = self.prof_title.text()
appdata.profname = self.drpdwn_prof_name.currentText() appdata.profname = self.drpdwn_prof_name.currentText()
appdata.semester = ( appdata.semester = (
self.sem_sommer.text() + " " + self.sem_year.text() self.sem_sommer.text() + " " + self.sem_year.text()
@@ -835,7 +864,7 @@ class Ui(Ui_Semesterapparat):
self.add_files() self.add_files()
appdata.apparat_adis_id = self.apparat_id_adis.text() appdata.apparat_adis_id = self.apparat_id_adis.text()
self.db.update_apparat(appdata) self.db.updateApparat(appdata)
self.update_app_media_list() self.update_app_media_list()
self.cancel_active_selection.click() self.cancel_active_selection.click()
@@ -980,13 +1009,14 @@ class Ui(Ui_Semesterapparat):
self.prof_tel_nr.clear() self.prof_tel_nr.clear()
return return
selected_prof = self.drpdwn_prof_name.currentText() selected_prof = self.drpdwn_prof_name.currentText()
data = self.db.get_prof_data(selected_prof) data = self.db.getProfData(selected_prof)
prof_title = data["prof_title"] ic(data)
prof_title = data[2]
if prof_title == "None": if prof_title == "None":
prof_title = "Kein Titel" prof_title = "Kein Titel"
self.drpdwn_prof_title.setCurrentText(prof_title) self.prof_title.setText(prof_title)
self.prof_tel_nr.setText(data["prof_tel"]) self.prof_tel_nr.setText(data[1])
self.prof_mail.setText(data["prof_mail"]) self.prof_mail.setText(data[0])
def get_index_of_value(self, table_widget, value): def get_index_of_value(self, table_widget, value):
for i in range(table_widget.rowCount()): for i in range(table_widget.rowCount()):
@@ -1010,21 +1040,20 @@ class Ui(Ui_Semesterapparat):
self.sem_year.setEnabled(False) self.sem_year.setEnabled(False)
self.dokument_list.setRowCount(0) self.dokument_list.setRowCount(0)
self.chkbx_show_del_media.setEnabled(True) self.chkbx_show_del_media.setEnabled(True)
appdata = self.db.get_app_data(appnr, appname) appdata = self.db.getApparatData(appnr, appname)
self.populate_frame(appdata) self.populate_frame(appdata)
self.btn_apparat_save.hide() self.btn_apparat_save.hide()
self.btn_reserve.show() self.btn_reserve.show()
self.drpdwn_app_nr.setDisabled(True) self.drpdwn_app_nr.setDisabled(True)
self.app_fach.setDisabled(True)
self.update_app_media_list() self.update_app_media_list()
self.update_documemt_list() self.update_documemt_list()
def update_documemt_list(self): def update_documemt_list(self):
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id( prof_id = self.db.getProfId(
self.drpdwn_prof_name.currentText().replace(", ", " ") self.drpdwn_prof_name.currentText().replace(", ", " ")
) )
files = self.db.get_files(app_id, prof_id) files = self.db.getFiles(app_id, prof_id)
for file in files: for file in files:
self.dokument_list.insertRow(0) self.dokument_list.insertRow(0)
self.dokument_list.setItem(0, 0, QtWidgets.QTableWidgetItem(file[0])) self.dokument_list.setItem(0, 0, QtWidgets.QTableWidgetItem(file[0]))
@@ -1054,7 +1083,7 @@ class Ui(Ui_Semesterapparat):
self.chkbx_show_del_media.setEnabled(True) self.chkbx_show_del_media.setEnabled(True)
self.drpdwn_app_nr.setEnabled(True) self.drpdwn_app_nr.setEnabled(True)
self.app_fach.setEnabled(True) self.app_fach.setEnabled(True)
self.app_fach.addItems([subject[1] for subject in self.db.get_subjects()]) self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()])
self.app_fach.addItem("") self.app_fach.addItem("")
self.app_fach.setCurrentText("") self.app_fach.setCurrentText("")
if self.tableWidget_apparat_media.rowCount() > 0: if self.tableWidget_apparat_media.rowCount() > 0:
@@ -1063,13 +1092,13 @@ class Ui(Ui_Semesterapparat):
for item in self.frame.findChildren(QtWidgets.QLineEdit): for item in self.frame.findChildren(QtWidgets.QLineEdit):
item.clear() item.clear()
self.drpdwn_app_nr.clear() self.drpdwn_app_nr.clear()
self.drpdwn_prof_title.clear() self.prof_title.clear()
self.drpdwn_prof_name.clear() self.drpdwn_prof_name.clear()
# set drop down menu for apparat numbers to only available numbers # set drop down menu for apparat numbers to only available numbers
self.drpdwn_app_nr.addItems( self.drpdwn_app_nr.addItems(
[str(i) for i in APP_NRS if i not in self.db.get_apparat_nrs()] [str(i) for i in APP_NRS if i not in self.db.getUnavailableApparatNumbers()]
) )
self.drpdwn_prof_title.addItems(PROF_TITLES)
valid_input = (0, 0, 0, 0, 0, 0) valid_input = (0, 0, 0, 0, 0, 0)
self.populate_prof_dropdown() self.populate_prof_dropdown()
# self.horizontalLayout_6.show() # self.horizontalLayout_6.show()
@@ -1112,9 +1141,9 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("Bitte mindestens ein Medium hinzufügen!") self.confirm_popup("Bitte mindestens ein Medium hinzufügen!")
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
# check if app_id is in database # check if app_id is in database
if not self.db.app_exists(app_id): if not self.db.checkApparatExists(app_id):
# create apparat # create apparat
self.btn_save_apparat() self.btn_save_apparat()
# create a thread that updates the progress label after each medium # create a thread that updates the progress label after each medium
@@ -1140,7 +1169,7 @@ class Ui(Ui_Semesterapparat):
# webdata = WebRequest().get_ppn(book).get_data() # webdata = WebRequest().get_ppn(book).get_data()
# bd: BookData = BibTextTransformer(mode).get_data(webdata).return_data() # bd: BookData = BibTextTransformer(mode).get_data(webdata).return_data()
# bd.signature = book # bd.signature = book
# self.db.add_medium(bookdata=bd, app_id=app_id, prof_id=prof_id) # self.db.addBookToDatabase(bookdata=bd, app_id=app_id, prof_id=prof_id)
# get all media list books # get all media list books
@@ -1166,9 +1195,9 @@ class Ui(Ui_Semesterapparat):
self.label_info.setText("Verfügbarkeit wird geprüft, bitte warten...") self.label_info.setText("Verfügbarkeit wird geprüft, bitte warten...")
self.label_info.show() self.label_info.show()
books = self.db.get_media( books = self.db.getBooks(
self.active_apparat(), self.active_apparat(),
self.db.get_prof_id(self.drpdwn_prof_name.currentText()), self.db.getProfId(self.drpdwn_prof_name.currentText()),
del_state=0, del_state=0,
) )
@@ -1190,14 +1219,15 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparat_media.setRowCount(0) self.tableWidget_apparat_media.setRowCount(0)
self.dokument_list.setRowCount(0) self.dokument_list.setRowCount(0)
self.frame.setEnabled(False) self.frame.setEnabled(False)
self.app_fach.setCurrentText("")
for child in self.frame.findChildren(QtWidgets.QLineEdit): for child in self.frame.findChildren(QtWidgets.QLineEdit):
child.clear() child.clear()
def update_app_media_list(self): def update_app_media_list(self):
deleted = 0 if not self.chkbx_show_del_media.isChecked() else 1 deleted = 0 if not self.chkbx_show_del_media.isChecked() else 1
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
books: list[dict[int, BookData, int]] = self.db.get_media( books: list[dict[int, BookData, int]] = self.db.getBooks(
app_id, prof_id, deleted app_id, prof_id, deleted
) )
@@ -1266,12 +1296,19 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparat_media.itemClicked.connect(self.open_link) self.tableWidget_apparat_media.itemClicked.connect(self.open_link)
def open_link(self, item): def open_link(self, item):
def __openLink(link):
if link == "":
return
if "http" not in link:
link = "https://" + link
webbrowser.open(link)
# get the name of the column # get the name of the column
columnname = self.tableWidget_apparat_media.horizontalHeaderItem( columnname = self.tableWidget_apparat_media.horizontalHeaderItem(
item.column() item.column()
).text() ).text()
if columnname == "Link": if columnname == "Link":
QtGui.QDesktopServices.openUrl(QtCore.QUrl(item.text())) __openLink(item.text())
else: else:
pass pass
@@ -1282,7 +1319,7 @@ class Ui(Ui_Semesterapparat):
clipboard.setText(text) clipboard.setText(text)
def populate_prof_dropdown(self): def populate_prof_dropdown(self):
profs = self.db.get_profs() profs = self.db.getProfs()
# add empty entry to dropdown and set it as current # add empty entry to dropdown and set it as current
self.drpdwn_prof_name.addItem("Kein Name") self.drpdwn_prof_name.addItem("Kein Name")
for prof in profs: for prof in profs:
@@ -1308,8 +1345,6 @@ class Ui(Ui_Semesterapparat):
# self.db.insert_file(files, self.active_apparat(), self.db.get_prof_id(self.drpdwn_prof_name.currentText())) # self.db.insert_file(files, self.active_apparat(), self.db.get_prof_id(self.drpdwn_prof_name.currentText()))
def open_document(self): def open_document(self):
print("trying to open document:")
_selected_doc_name = "" _selected_doc_name = ""
_selected_doc_filetype = "" _selected_doc_filetype = ""
try: try:
@@ -1325,8 +1360,8 @@ class Ui(Ui_Semesterapparat):
except AttributeError: except AttributeError:
self.confirm_popup("Bitte erst ein Dokument auswählen!") self.confirm_popup("Bitte erst ein Dokument auswählen!")
return return
print(_selected_doc_name, _selected_doc_filetype)
if not _selected_doc_location == "Database": if not _selected_doc_location == "Database":
print("not in database")
path = Path(_selected_doc_location) path = Path(_selected_doc_location)
path = path + "/" + _selected_doc_name path = path + "/" + _selected_doc_name
if os.getenv("OS") == "Windows_NT": if os.getenv("OS") == "Windows_NT":
@@ -1336,31 +1371,19 @@ class Ui(Ui_Semesterapparat):
path = path.resolve() path = path.resolve()
os.system(f"open {path}") os.system(f"open {path}")
else: else:
print("in database")
try: try:
self.db.recreate_file(_selected_doc_name, self.active_apparat()) file_loc = self.db.recreateFile(_selected_doc_name, "71",filetype=_selected_doc_filetype)
print(f"filename is {file_loc}")
except Exception as e: except Exception as e:
self.logger.log_exception(e) print(e)
path = config.save_path + _selected_doc_name path = Path(file_loc)
# if ~ in path, replace it with the home directory if os.getenv("OS") == "Windows_NT":
if "~" in path: path = path.resolve()
path = path.replace("~", str(Path.home())) os.startfile(path)
path = Path(path) else:
if os.getenv("OS") == "Windows_NT": path = path.resolve()
path = path.resolve() os.system(f"open {path}")
os.startfile(path)
else:
path = path.resolve()
os.system(f"open {path}")
# filebytes = self.db.get_blob(
# _selected_doc_name,
# self.active_apparat(),
# )
# # use io.BytesIO to create a file-like object from the bytes and open it in the respective program
# file = io.BytesIO(filebytes)
# file.name = _selected_doc_name
# QtGui.QDesktopServices.openUrl(QtCore.QUrl(file))
# print(type(filebytes))
def add_media_from_file(self): def add_media_from_file(self):
def __open_dialog(signatures): def __open_dialog(signatures):
@@ -1408,7 +1431,7 @@ class Ui(Ui_Semesterapparat):
delete=False, suffix="." + file_type delete=False, suffix="." + file_type
) )
temp_file.write( temp_file.write(
self.db.get_blob(file_name, int(self.active_apparat())) self.db.getBlob(file_name, int(self.active_apparat()))
) )
temp_file.close() temp_file.close()
file = temp_file.name file = temp_file.name
@@ -1418,20 +1441,20 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("PDF Dateien werden nochnicht unterstützt!") self.confirm_popup("PDF Dateien werden nochnicht unterstützt!")
return return
if file_type == "csv": if file_type == "csv":
signatures = utils.csv_to_list(file) signatures = csv_to_list(file)
data = __open_dialog(signatures) data = __open_dialog(signatures)
# get the app_id and prof_id # get the app_id and prof_id
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
# add the data to the database # add the data to the database
for book in data: for book in data:
if type(book) != BookData: if type(book) != BookData:
continue continue
self.db.add_medium( self.db.addBookToDatabase(
bookdata=book, app_id=app_id, prof_id=prof_id bookdata=book, app_id=app_id, prof_id=prof_id
) )
if file_type == "docx": if file_type == "docx":
data = utils.word_docx_to_csv(file) data = word_docx_to_csv(file)
signatures = [ signatures = [
i i
for i in data["Standnummer"].values for i in data["Standnummer"].values
@@ -1443,12 +1466,12 @@ class Ui(Ui_Semesterapparat):
return return
# get the app_id and prof_id # get the app_id and prof_id
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
# add the data to the database # add the data to the database
for book in data: for book in data:
if type(book) != BookData: if type(book) != BookData:
continue continue
self.db.add_medium( self.db.addBookToDatabase(
bookdata=book, app_id=app_id, prof_id=prof_id bookdata=book, app_id=app_id, prof_id=prof_id
) )
self.update_app_media_list() self.update_app_media_list()
@@ -1461,9 +1484,9 @@ class Ui(Ui_Semesterapparat):
"Bitte warten, bis alle Medien hinzugefügt wurden" "Bitte warten, bis alle Medien hinzugefügt wurden"
) )
app_id = self.active_apparat() app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
# check if apparat in database # check if apparat in database
if not self.db.app_exists(app_id): if not app_id in self.db.getUnavailableApparatNumbers():
# create apparat # create apparat
self.btn_save_apparat() self.btn_save_apparat()
if self.dokument_list.rowCount() == 0: if self.dokument_list.rowCount() == 0:
@@ -1490,13 +1513,13 @@ class Ui(Ui_Semesterapparat):
temp_file = tempfile.NamedTemporaryFile( temp_file = tempfile.NamedTemporaryFile(
delete=False, suffix="." + file_type delete=False, suffix="." + file_type
) )
temp_file.write(self.db.get_blob(file_name, int(self.active_apparat()))) temp_file.write(self.db.getBlob(file_name, int(self.active_apparat())))
temp_file.close() temp_file.close()
file = temp_file.name file = temp_file.name
print(file) print(file)
if file_type == "pdf": if file_type == "pdf":
# Todo: implement parser here # Todo: implement parser here
self.confirm_popup("PDF Dateien werden nochnicht unterstützt!") self.confirm_popup("PDF Dateien werden noch nicht unterstützt!")
return return
if file_type == "csv": if file_type == "csv":
signatures = csv_to_list(file) signatures = csv_to_list(file)
@@ -1535,12 +1558,12 @@ class Ui(Ui_Semesterapparat):
def btn_save_apparat(self): def btn_save_apparat(self):
def __clear_fields(): def __clear_fields():
self.drpdwn_app_nr.clear() self.drpdwn_app_nr.clear()
self.drpdwn_prof_title.clear() self.prof_title.clear()
self.drpdwn_prof_name.clearMask() self.drpdwn_prof_name.clearMask()
self.app_name.clear() self.app_name.clear()
self.prof_mail.clear() self.prof_mail.clear()
self.prof_tel_nr.clear() self.prof_tel_nr.clear()
self.app_fach.clear() self.app_fach.setCurrentText("")
self.app_name.clear() self.app_name.clear()
self.sem_year.clear() self.sem_year.clear()
self.dokument_list.setRowCount(0) self.dokument_list.setRowCount(0)
@@ -1561,8 +1584,8 @@ class Ui(Ui_Semesterapparat):
appd.appnr = self.active_apparat() appd.appnr = self.active_apparat()
appd.prof_title = ( appd.prof_title = (
None None
if self.drpdwn_prof_title.currentText() == "Kein Titel" if self.prof_title.text() == ""
else self.drpdwn_prof_title.currentText() else self.prof_title.text()
) )
appd.profname = self.drpdwn_prof_name.currentText() appd.profname = self.drpdwn_prof_name.currentText()
appd.appname = self.app_name.text() appd.appname = self.app_name.text()
@@ -1570,35 +1593,37 @@ class Ui(Ui_Semesterapparat):
appd.dauerapp = 1 if self.check_eternal_app.isChecked() else 0 appd.dauerapp = 1 if self.check_eternal_app.isChecked() else 0
appd.prof_tel = self.prof_tel_nr.text() appd.prof_tel = self.prof_tel_nr.text()
appd.prof_mail = self.prof_mail.text() appd.prof_mail = self.prof_mail.text()
app_fach = self.app_fach.currentText() appd.app_fach = self.app_fach.currentText()
curr_fach_alias = self.db.get_subjects_and_aliases() appd.erstellsemester = self.generateSemester()
for fach in curr_fach_alias: # curr_fach_alias = self.db.get_subjects_and_aliases()
if app_fach in fach: # for fach in curr_fach_alias:
appd.app_fach = app_fach # if app_fach in fach:
break # appd.app_fach = app_fach
else: # break
#create a popup to ask for the correct subject # else:
dialog = QtWidgets.QDialog() # #create a popup to ask for the correct subject
popup = new_subject_ui() # dialog = QtWidgets.QDialog()
popup.setupUi(dialog) # popup = new_subject_ui()
new_subject = popup.return_state() # popup.setupUi(dialog)
dialog.exec() # new_subject = popup.return_state()
if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: # dialog.exec()
appd.app_fach = new_subject # if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted:
self.db.add_subject(new_subject) # appd.app_fach = new_subject
else: # self.db.add_subject(new_subject)
return # else:
# return
appd.deleted = 0 appd.deleted = 0
appd.prof_adis_id = self.prof_id_adis.text() appd.prof_adis_id = self.prof_id_adis.text()
appd.apparat_adis_id = self.apparat_id_adis.text() appd.apparat_adis_id = self.apparat_id_adis.text()
self.add_files()
if not self.validate_fields():
pass
self.db.create_apparat(appd)
if self.dokument_list.rowCount() > 0: if self.dokument_list.rowCount() > 0:
self.add_files() self.add_files()
appdata = self.db.get_apparats() if not self.validate_fields():
pass
self.db.createApparat(appd)
if self.dokument_list.rowCount() > 0:
self.add_files()
appdata = self.db.getAllAparats()
# merge self.appdata and appdata, remove duplicates # merge self.appdata and appdata, remove duplicates
self.apparats = list(set(self.apparats + appdata)) self.apparats = list(set(self.apparats + appdata))
self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True)
@@ -1623,7 +1648,7 @@ class Ui(Ui_Semesterapparat):
} }
) )
self.dokument_list.item(i, 2).setText("") self.dokument_list.item(i, 2).setText("")
self.db.insert_file(files, self.active_apparat(), self.db.get_prof_id(self.drpdwn_prof_name.currentText())) self.db.insertFile(files, self.active_apparat(), self.db.getProfId(self.drpdwn_prof_name.currentText()))
def update_apparat_list(self): def update_apparat_list(self):
# get a list of new apparats based on self.apparats and self.old_apparats # get a list of new apparats based on self.apparats and self.old_apparats
@@ -1640,7 +1665,7 @@ class Ui(Ui_Semesterapparat):
def insert_apparat_into_table(self, apparat): def insert_apparat_into_table(self, apparat):
def __dauer_check(apparat): def __dauer_check(apparat):
result = self.db.is_eternal(apparat[0]) result = self.db.isEternal(apparat[0])
return "Ja" if result == ("True" or "1") else "Nein" return "Ja" if result == ("True" or "1") else "Nein"
self.tableWidget_apparate.insertRow(0) self.tableWidget_apparate.insertRow(0)
@@ -1654,7 +1679,7 @@ class Ui(Ui_Semesterapparat):
0, 0,
2, 2,
QtWidgets.QTableWidgetItem( QtWidgets.QTableWidgetItem(
self.db.get_prof_name_by_id(apparat[2], add_title=False) self.db.getProfNameById(apparat[2], add_title=False)
), ),
) )
self.tableWidget_apparate.setItem( self.tableWidget_apparate.setItem(
@@ -1668,10 +1693,18 @@ class Ui(Ui_Semesterapparat):
0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat)) 0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat))
) )
self.tableWidget_apparate.setItem( self.tableWidget_apparate.setItem(
0, 5, QtWidgets.QTableWidgetItem(str(apparat[13])) 0, 5, QtWidgets.QTableWidgetItem(str(apparat[11]))
) )
self.logger.log_info(f"Inserted apparat {apparat[4]}") self.logger.log_info(f"Inserted apparat {apparat[4]}")
def calendar_context_menu(self):
#create a context menu for the calendar
menu = QtWidgets.QMenu()
create_reminder = menu.addAction("Erinnerung erstellen")
create_reminder.triggered.connect(self.reminder(date=self.calendarWidget.selectedDate().toString("yyyy-MM-dd")))
menu.exec(QtGui.QCursor.pos())
return menu
def open_context_menu(self, position): def open_context_menu(self, position):
menu = QtWidgets.QMenu() menu = QtWidgets.QMenu()
extend_action = menu.addAction("Verlängern") extend_action = menu.addAction("Verlängern")
@@ -1687,6 +1720,7 @@ class Ui(Ui_Semesterapparat):
menu.exec(self.tableWidget_apparate.mapToGlobal(position)) menu.exec(self.tableWidget_apparate.mapToGlobal(position))
def reminder(self): def reminder(self):
self.logger.log_info("Opening reminder dialog")
dialog = QtWidgets.QDialog() dialog = QtWidgets.QDialog()
reminder = reminder_ui() reminder = reminder_ui()
reminder.setupUi(dialog) reminder.setupUi(dialog)
@@ -1694,7 +1728,7 @@ class Ui(Ui_Semesterapparat):
if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = reminder.return_message() data = reminder.return_message()
print(data) print(data)
self.db.add_message( self.db.addMessage(
data, data,
self.active_user, self.active_user,
self.active_apparat if self.active_apparat() != "" else None, self.active_apparat if self.active_apparat() != "" else None,
@@ -1707,7 +1741,7 @@ class Ui(Ui_Semesterapparat):
# self.update_app_media_list() # self.update_app_media_list()
def get_reminders(self): def get_reminders(self):
messages = self.db.get_messages() messages = self.db.getMessages()
self.logger.log_info(f"Got {len(messages)} messages from database") self.logger.log_info(f"Got {len(messages)} messages from database")
self.calendarWidget.setMessages(messages) self.calendarWidget.setMessages(messages)
self.calendarWidget.updateCells() self.calendarWidget.updateCells()
@@ -1722,12 +1756,12 @@ class Ui(Ui_Semesterapparat):
return return
self.message_box.setText(message["message"]) self.message_box.setText(message["message"])
self.line_app_info.setText( self.line_app_info.setText(
message["apparatnr"] if message["apparatnr"] != None else "/" message["appnr"] if message["appnr"] != None else "/"
) )
def __delete_message(): def __delete_message():
message = messages[self.spin_select_message.value() - 1] message = messages[self.spin_select_message.value() - 1]
self.db.delete_message(message["id"]) self.db.deleteMessage(message["id"])
# remove message from list # remove message from list
messages.remove(message) messages.remove(message)
self.spin_select_message.setMaximum(len(messages)) self.spin_select_message.setMaximum(len(messages))
@@ -1736,7 +1770,7 @@ class Ui(Ui_Semesterapparat):
selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd") selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd")
print(selected_date) print(selected_date)
messages = self.db.get_messages(selected_date) messages = self.db.getMessages(selected_date)
if messages == []: if messages == []:
self.message_frame.hide() if self.message_frame.isVisible() else None self.message_frame.hide() if self.message_frame.isVisible() else None
return return
@@ -1773,7 +1807,7 @@ class Ui(Ui_Semesterapparat):
def reload(self): def reload(self):
#create a new connection to the database, refresh table data and replace the old connection #create a new connection to the database, refresh table data and replace the old connection
self.db = Database() self.db = Database()
self.apparats = self.db.get_all_apparts(deleted=0) self.apparats = self.db.getAllAparats(deleted=0)
self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True)
self.tableWidget_apparate.setRowCount(0) self.tableWidget_apparate.setRowCount(0)
for apparat in self.apparats: for apparat in self.apparats:
@@ -1793,12 +1827,12 @@ class Ui(Ui_Semesterapparat):
book = self.tableWidget_apparat_media.item( book = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1 self.tableWidget_apparat_media.currentRow(), 1
).text() ).text()
book_id = self.db.request_medium( book_id = self.db.getBookIdBasedOnSignature(
app_id=self.active_apparat(), app_id=self.active_apparat(),
signature=book, signature=book,
prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()), prof_id=self.db.getProfId(self.drpdwn_prof_name.currentText()),
) )
data = self.db.get_specific_book(book_id) data = self.db.getBook(book_id)
widget = QtWidgets.QDialog() widget = QtWidgets.QDialog()
bookedit = edit_bookdata_ui() bookedit = edit_bookdata_ui()
bookedit.setupUi(widget) bookedit.setupUi(widget)
@@ -1809,7 +1843,7 @@ class Ui(Ui_Semesterapparat):
if widget.result() == QtWidgets.QDialog.DialogCode.Accepted: if widget.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = bookedit.get_data() data = bookedit.get_data()
print(data) print(data)
self.db.update_bookdata(data, book_id) self.db.updateBookdata(data, book_id)
# self.db.update_bookdata(data) # self.db.update_bookdata(data)
print("accepted") print("accepted")
self.update_app_media_list() self.update_app_media_list()
@@ -1824,17 +1858,17 @@ class Ui(Ui_Semesterapparat):
signature = self.tableWidget_apparat_media.item( signature = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1 self.tableWidget_apparat_media.currentRow(), 1
).text() ).text()
# bookdata= self.db.request_medium(selected_apparat_id,prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()),signature=signature) # bookdata= self.db.getBookIdBasedOnSignature(selected_apparat_id,prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()),signature=signature)
book_id = self.db.request_medium( book_id = self.db.getBookIdBasedOnSignature(
selected_apparat_id, selected_apparat_id,
prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()), prof_id=self.db.getProfId(self.drpdwn_prof_name.currentText()),
signature=signature, signature=signature,
) )
message = f'Soll das Medium "{self.tableWidget_apparat_media.item(self.tableWidget_apparat_media.currentRow(),0).text()}" wirklich gelöscht werden?' message = f'Soll das Medium "{self.tableWidget_apparat_media.item(self.tableWidget_apparat_media.currentRow(),0).text()}" wirklich gelöscht werden?'
state = self.confirm_popup(message) state = self.confirm_popup(message)
print(state) print(state)
if state == 1: if state == 1:
self.db.delete_medium(book_id) self.db.deleteBook(book_id)
self.update_app_media_list() self.update_app_media_list()
pass pass
@@ -1862,7 +1896,7 @@ class Ui(Ui_Semesterapparat):
# apparat[7]=data["dauerapp"] # apparat[7]=data["dauerapp"]
# break # break
# self.old_apparats = self.apparats # self.old_apparats = self.apparats
self.db.set_new_sem_date( self.db.setNewSemesterDate(
selected_apparat_id, data["semester"], dauerapp=data["dauerapp"] selected_apparat_id, data["semester"], dauerapp=data["dauerapp"]
) )
else: else:
@@ -1881,13 +1915,13 @@ class Ui(Ui_Semesterapparat):
).text() ).text()
general_data = { general_data = {
"Appname": self.app_name.text(), "Appname": self.app_name.text(),
"AppSubject": self.app_fach.text(), "AppSubject": self.app_fach.currentText(),
"appnr": active_apparat_id, "appnr": active_apparat_id,
} }
print(active_apparat_id) print(active_apparat_id)
mail_prev.appid = active_apparat_id mail_prev.appid = active_apparat_id
base_data = self.db.get_prof_data(id=active_apparat_id) base_data = self.db.getProfData(id=active_apparat_id)
profname = self.db.get_prof_name_by_id(base_data["id"]) profname = self.db.getProfNameById(base_data["id"])
profname = profname.split(" ") profname = profname.split(" ")
profname = f"{profname[1]} {profname[0]}" profname = f"{profname[1]} {profname[0]}"
pass_data = { pass_data = {
@@ -1908,7 +1942,7 @@ class Ui(Ui_Semesterapparat):
state = self.confirm_popup(message) state = self.confirm_popup(message)
print(state) print(state)
if state == 1: if state == 1:
self.db.delete_apparat( self.db.deleteApparat(
selected_apparat_id, self.generateSemester(today=True) selected_apparat_id, self.generateSemester(today=True)
) )
# delete the corresponding entry from self.apparats # delete the corresponding entry from self.apparats

View File

@@ -1,4 +1,4 @@
# Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\Semesterapparate-refactor\src\ui\semesterapparat_ui.ui' # Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\SemesterapparatsManager\src\ui\semesterapparat_ui.ui'
# #
# Created by: PyQt6 UI code generator 6.3.1 # Created by: PyQt6 UI code generator 6.3.1
# #
@@ -183,15 +183,6 @@ class Ui_MainWindow(object):
self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame.setObjectName("frame") self.frame.setObjectName("frame")
self.drpdwn_prof_title = QtWidgets.QComboBox(self.frame)
self.drpdwn_prof_title.setGeometry(QtCore.QRect(110, 50, 69, 22))
font = QtGui.QFont()
font.setPointSize(9)
font.setBold(False)
font.setWeight(50)
self.drpdwn_prof_title.setFont(font)
self.drpdwn_prof_title.setEditable(True)
self.drpdwn_prof_title.setObjectName("drpdwn_prof_title")
self.label_5 = QtWidgets.QLabel(self.frame) self.label_5 = QtWidgets.QLabel(self.frame)
self.label_5.setGeometry(QtCore.QRect(250, 20, 91, 21)) self.label_5.setGeometry(QtCore.QRect(250, 20, 91, 21))
font = QtGui.QFont() font = QtGui.QFont()
@@ -487,12 +478,27 @@ class Ui_MainWindow(object):
self.gridLayout_6.setContentsMargins(0, 0, 0, 0) self.gridLayout_6.setContentsMargins(0, 0, 0, 0)
self.gridLayout_6.setObjectName("gridLayout_6") self.gridLayout_6.setObjectName("gridLayout_6")
self.app_fach = QtWidgets.QComboBox(self.gridLayoutWidget_5) self.app_fach = QtWidgets.QComboBox(self.gridLayoutWidget_5)
self.app_fach.setMaximumSize(QtCore.QSize(16777215, 20))
font = QtGui.QFont()
font.setPointSize(9)
font.setBold(False)
font.setWeight(50)
self.app_fach.setFont(font)
self.app_fach.setObjectName("app_fach") self.app_fach.setObjectName("app_fach")
self.gridLayout_6.addWidget(self.app_fach, 0, 0, 1, 1) self.gridLayout_6.addWidget(self.app_fach, 0, 0, 1, 1)
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.gridLayout_6.addItem(spacerItem2, 0, 1, 1, 1) self.gridLayout_6.addItem(spacerItem2, 0, 1, 1, 1)
self.prof_title = QtWidgets.QLineEdit(self.frame)
self.prof_title.setGeometry(QtCore.QRect(110, 50, 71, 20))
font = QtGui.QFont()
font.setPointSize(9)
font.setBold(False)
font.setWeight(50)
self.prof_title.setFont(font)
self.prof_title.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus)
self.prof_title.setObjectName("prof_title")
self.mail_mand.raise_()
self._mand.raise_() self._mand.raise_()
self.drpdwn_prof_title.raise_()
self.label_5.raise_() self.label_5.raise_()
self.sem_winter.raise_() self.sem_winter.raise_()
self.label_4.raise_() self.label_4.raise_()
@@ -508,7 +514,6 @@ class Ui_MainWindow(object):
self.label_8.raise_() self.label_8.raise_()
self.label_9.raise_() self.label_9.raise_()
self.label_10.raise_() self.label_10.raise_()
self.mail_mand.raise_()
self.telnr_mand.raise_() self.telnr_mand.raise_()
self.profname_mand.raise_() self.profname_mand.raise_()
self.appname_mand.raise_() self.appname_mand.raise_()
@@ -523,6 +528,7 @@ class Ui_MainWindow(object):
self.formLayoutWidget_2.raise_() self.formLayoutWidget_2.raise_()
self.check_send_mail.raise_() self.check_send_mail.raise_()
self.frame_3.raise_() self.frame_3.raise_()
self.prof_title.raise_()
self.frame.raise_() self.frame.raise_()
self.dokument_list.raise_() self.dokument_list.raise_()
self.gridLayout_2.addWidget(self.app_group_box, 1, 0, 1, 1) self.gridLayout_2.addWidget(self.app_group_box, 1, 0, 1, 1)
@@ -729,8 +735,6 @@ class Ui_MainWindow(object):
self.stackedWidget_4.setObjectName("stackedWidget_4") self.stackedWidget_4.setObjectName("stackedWidget_4")
self.stackedWidget_4Page1 = QtWidgets.QWidget() self.stackedWidget_4Page1 = QtWidgets.QWidget()
self.stackedWidget_4Page1.setObjectName("stackedWidget_4Page1") self.stackedWidget_4Page1.setObjectName("stackedWidget_4Page1")
#set focus to page 1
self.stackedWidget_4.setCurrentIndex(0)
self.tabWidget_3 = QtWidgets.QTabWidget(self.stackedWidget_4Page1) self.tabWidget_3 = QtWidgets.QTabWidget(self.stackedWidget_4Page1)
self.tabWidget_3.setGeometry(QtCore.QRect(780, 10, 441, 441)) self.tabWidget_3.setGeometry(QtCore.QRect(780, 10, 441, 441))
self.tabWidget_3.setObjectName("tabWidget_3") self.tabWidget_3.setObjectName("tabWidget_3")
@@ -954,7 +958,7 @@ class Ui_MainWindow(object):
spacerItem14 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) spacerItem14 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.gridLayout_11.addItem(spacerItem14, 0, 4, 1, 1) self.gridLayout_11.addItem(spacerItem14, 0, 4, 1, 1)
self.edit_faculty_member = QtWidgets.QFrame(self.tab_5) self.edit_faculty_member = QtWidgets.QFrame(self.tab_5)
self.edit_faculty_member.setGeometry(QtCore.QRect(10, 60, 1051, 191)) self.edit_faculty_member.setGeometry(QtCore.QRect(10, 60, 1051, 241))
self.edit_faculty_member.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.edit_faculty_member.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.edit_faculty_member.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.edit_faculty_member.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.edit_faculty_member.setObjectName("edit_faculty_member") self.edit_faculty_member.setObjectName("edit_faculty_member")
@@ -970,6 +974,7 @@ class Ui_MainWindow(object):
self.label_43.setObjectName("label_43") self.label_43.setObjectName("label_43")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_43) self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_43)
self.edit_faculty_member_new_title = QtWidgets.QComboBox(self.gridLayoutWidget_11) self.edit_faculty_member_new_title = QtWidgets.QComboBox(self.gridLayoutWidget_11)
self.edit_faculty_member_new_title.setEditable(True)
self.edit_faculty_member_new_title.setObjectName("edit_faculty_member_new_title") self.edit_faculty_member_new_title.setObjectName("edit_faculty_member_new_title")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.edit_faculty_member_new_title) self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.edit_faculty_member_new_title)
self.label_44 = QtWidgets.QLabel(self.gridLayoutWidget_11) self.label_44 = QtWidgets.QLabel(self.gridLayoutWidget_11)
@@ -1021,12 +1026,12 @@ class Ui_MainWindow(object):
self.label_48 = QtWidgets.QLabel(self.gridLayoutWidget_11) self.label_48 = QtWidgets.QLabel(self.gridLayoutWidget_11)
self.label_48.setObjectName("label_48") self.label_48.setObjectName("label_48")
self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_48) self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_48)
self.lineEdit = QtWidgets.QLineEdit(self.gridLayoutWidget_11) self.user_faculty_member_new_mail = QtWidgets.QLineEdit(self.gridLayoutWidget_11)
self.lineEdit.setObjectName("lineEdit") self.user_faculty_member_new_mail.setObjectName("user_faculty_member_new_mail")
self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit) self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.user_faculty_member_new_mail)
self.lineEdit_5 = QtWidgets.QLineEdit(self.gridLayoutWidget_11) self.user_faculty_member_new_telnr = QtWidgets.QLineEdit(self.gridLayoutWidget_11)
self.lineEdit_5.setObjectName("lineEdit_5") self.user_faculty_member_new_telnr.setObjectName("user_faculty_member_new_telnr")
self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_5) self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.user_faculty_member_new_telnr)
self.gridLayout_12.addLayout(self.formLayout_5, 2, 4, 1, 1) self.gridLayout_12.addLayout(self.formLayout_5, 2, 4, 1, 1)
self.label_41 = QtWidgets.QLabel(self.gridLayoutWidget_11) self.label_41 = QtWidgets.QLabel(self.gridLayoutWidget_11)
self.label_41.setObjectName("label_41") self.label_41.setObjectName("label_41")
@@ -1150,7 +1155,7 @@ class Ui_MainWindow(object):
self.btn_copy_adis_command.setAccessibleDescription("") self.btn_copy_adis_command.setAccessibleDescription("")
self.btn_copy_adis_command.setAutoFillBackground(False) self.btn_copy_adis_command.setAutoFillBackground(False)
icon = QtGui.QIcon() icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("c:\\Users\\aky547\\GitHub\\Semesterapparate-refactor\\src\\ui\\../../../.designer/backup/icons/information.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) icon.addPixmap(QtGui.QPixmap("c:\\Users\\aky547\\GitHub\\SemesterapparatsManager\\src\\ui\\../../../.designer/backup/icons/information.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
self.btn_copy_adis_command.setIcon(icon) self.btn_copy_adis_command.setIcon(icon)
self.btn_copy_adis_command.setCheckable(False) self.btn_copy_adis_command.setCheckable(False)
self.btn_copy_adis_command.setChecked(False) self.btn_copy_adis_command.setChecked(False)
@@ -1226,8 +1231,7 @@ class Ui_MainWindow(object):
self.stackedWidget_4.setCurrentIndex(1) self.stackedWidget_4.setCurrentIndex(1)
self.tabWidget_3.setCurrentIndex(1) self.tabWidget_3.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.drpdwn_app_nr, self.drpdwn_prof_title) MainWindow.setTabOrder(self.drpdwn_app_nr, self.drpdwn_prof_name)
MainWindow.setTabOrder(self.drpdwn_prof_title, self.drpdwn_prof_name)
MainWindow.setTabOrder(self.drpdwn_prof_name, self.prof_mail) MainWindow.setTabOrder(self.drpdwn_prof_name, self.prof_mail)
MainWindow.setTabOrder(self.prof_mail, self.prof_tel_nr) MainWindow.setTabOrder(self.prof_mail, self.prof_tel_nr)
MainWindow.setTabOrder(self.prof_tel_nr, self.app_name) MainWindow.setTabOrder(self.prof_tel_nr, self.app_name)
@@ -1265,9 +1269,9 @@ class Ui_MainWindow(object):
MainWindow.setTabOrder(self.faculty_member_oldmail, self.edit_faculty_member_new_title) MainWindow.setTabOrder(self.faculty_member_oldmail, self.edit_faculty_member_new_title)
MainWindow.setTabOrder(self.edit_faculty_member_new_title, self.edit_faculty_member_new_surname) MainWindow.setTabOrder(self.edit_faculty_member_new_title, self.edit_faculty_member_new_surname)
MainWindow.setTabOrder(self.edit_faculty_member_new_surname, self.user_faculty_member_new_name) MainWindow.setTabOrder(self.edit_faculty_member_new_surname, self.user_faculty_member_new_name)
MainWindow.setTabOrder(self.user_faculty_member_new_name, self.lineEdit) MainWindow.setTabOrder(self.user_faculty_member_new_name, self.user_faculty_member_new_mail)
MainWindow.setTabOrder(self.lineEdit, self.lineEdit_5) MainWindow.setTabOrder(self.user_faculty_member_new_mail, self.user_faculty_member_new_telnr)
MainWindow.setTabOrder(self.lineEdit_5, self.update_faculty_member) MainWindow.setTabOrder(self.user_faculty_member_new_telnr, self.update_faculty_member)
MainWindow.setTabOrder(self.update_faculty_member, self.box_fach) MainWindow.setTabOrder(self.update_faculty_member, self.box_fach)
MainWindow.setTabOrder(self.box_fach, self.box_person) MainWindow.setTabOrder(self.box_fach, self.box_person)
MainWindow.setTabOrder(self.box_person, self.btn_search) MainWindow.setTabOrder(self.box_person, self.btn_search)

View File

@@ -71,7 +71,7 @@ class Ui_Dialog(object):
hashed_password = hashlib.sha256( hashed_password = hashlib.sha256(
password.encode() password.encode()
).hexdigest() ).hexdigest()
if len(db.get_users()) == 0: if len(db.getUsers()) == 0:
AdminCommands().create_admin() AdminCommands().create_admin()
self.lresult = 1 # Indicate successful login self.lresult = 1 # Indicate successful login
self.lusername = username self.lusername = username
@@ -80,7 +80,6 @@ class Ui_Dialog(object):
self.lresult = 1 # Indicate successful login self.lresult = 1 # Indicate successful login
self.lusername = username self.lusername = username
self.dialog.accept() self.dialog.accept()
db.close()
else: else:
# Credentials are invalid, display a warning # Credentials are invalid, display a warning
if username == "" or password == "": if username == "" or password == "":

View File

@@ -376,26 +376,6 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<widget class="QComboBox" name="drpdwn_prof_title">
<property name="geometry">
<rect>
<x>110</x>
<y>50</y>
<width>69</width>
<height>22</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="geometry"> <property name="geometry">
<rect> <rect>
@@ -1099,7 +1079,21 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QComboBox" name="app_fach"/> <widget class="QComboBox" name="app_fach">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
</widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="horizontalSpacer_7"> <spacer name="horizontalSpacer_7">
@@ -1117,8 +1111,28 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QLineEdit" name="prof_title">
<property name="geometry">
<rect>
<x>110</x>
<y>50</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
<zorder>mail_mand</zorder>
<zorder>_mand</zorder> <zorder>_mand</zorder>
<zorder>drpdwn_prof_title</zorder>
<zorder>label_5</zorder> <zorder>label_5</zorder>
<zorder>sem_winter</zorder> <zorder>sem_winter</zorder>
<zorder>label_4</zorder> <zorder>label_4</zorder>
@@ -1134,7 +1148,6 @@
<zorder>label_8</zorder> <zorder>label_8</zorder>
<zorder>label_9</zorder> <zorder>label_9</zorder>
<zorder>label_10</zorder> <zorder>label_10</zorder>
<zorder>mail_mand</zorder>
<zorder>telnr_mand</zorder> <zorder>telnr_mand</zorder>
<zorder>profname_mand</zorder> <zorder>profname_mand</zorder>
<zorder>appname_mand</zorder> <zorder>appname_mand</zorder>
@@ -1149,6 +1162,7 @@
<zorder>formLayoutWidget_2</zorder> <zorder>formLayoutWidget_2</zorder>
<zorder>check_send_mail</zorder> <zorder>check_send_mail</zorder>
<zorder>frame_3</zorder> <zorder>frame_3</zorder>
<zorder>prof_title</zorder>
</widget> </widget>
<zorder>frame</zorder> <zorder>frame</zorder>
<zorder>dokument_list</zorder> <zorder>dokument_list</zorder>
@@ -2230,7 +2244,7 @@
<x>10</x> <x>10</x>
<y>60</y> <y>60</y>
<width>1051</width> <width>1051</width>
<height>191</height> <height>241</height>
</rect> </rect>
</property> </property>
<property name="frameShape"> <property name="frameShape">
@@ -2259,7 +2273,11 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="edit_faculty_member_new_title"/> <widget class="QComboBox" name="edit_faculty_member_new_title">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_44"> <widget class="QLabel" name="label_44">
@@ -2354,10 +2372,10 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="user_faculty_member_new_mail"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_5"/> <widget class="QLineEdit" name="user_faculty_member_new_telnr"/>
</item> </item>
</layout> </layout>
</item> </item>
@@ -2832,7 +2850,6 @@
</widget> </widget>
<tabstops> <tabstops>
<tabstop>drpdwn_app_nr</tabstop> <tabstop>drpdwn_app_nr</tabstop>
<tabstop>drpdwn_prof_title</tabstop>
<tabstop>drpdwn_prof_name</tabstop> <tabstop>drpdwn_prof_name</tabstop>
<tabstop>prof_mail</tabstop> <tabstop>prof_mail</tabstop>
<tabstop>prof_tel_nr</tabstop> <tabstop>prof_tel_nr</tabstop>
@@ -2871,8 +2888,8 @@
<tabstop>edit_faculty_member_new_title</tabstop> <tabstop>edit_faculty_member_new_title</tabstop>
<tabstop>edit_faculty_member_new_surname</tabstop> <tabstop>edit_faculty_member_new_surname</tabstop>
<tabstop>user_faculty_member_new_name</tabstop> <tabstop>user_faculty_member_new_name</tabstop>
<tabstop>lineEdit</tabstop> <tabstop>user_faculty_member_new_mail</tabstop>
<tabstop>lineEdit_5</tabstop> <tabstop>user_faculty_member_new_telnr</tabstop>
<tabstop>update_faculty_member</tabstop> <tabstop>update_faculty_member</tabstop>
<tabstop>box_fach</tabstop> <tabstop>box_fach</tabstop>
<tabstop>box_person</tabstop> <tabstop>box_person</tabstop>

View File

@@ -64,4 +64,4 @@ class Ui_Form(object):
def delete_message(self): def delete_message(self):
db = Database() db = Database()
print("deleting message") print("deleting message")
db.delete_message(self.hidden_id.text()) db.deleteMessage(self.hidden_id.text())