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 time
from pathlib import Path
import webbrowser
from natsort import natsorted
from omegaconf import OmegaConf
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import QDate, QThread, pyqtSignal
from PyQt6.QtGui import QColor, QRegularExpressionValidator
from src.logic import c_sort
from src.backend.database import Database
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.threads import BookGrabber,AvailChecker
from src.ui import (
@@ -121,6 +120,7 @@ class MessageCalendar(QtWidgets.QCalendarWidget):
)
class Ui(Ui_Semesterapparat):
# use the Ui_MainWindow class from mainwindow.py
def __init__(self, MainWindow, username: str) -> None:
@@ -158,6 +158,10 @@ class Ui(Ui_Semesterapparat):
)
self.calendarWidget.setObjectName("MessageCalendar")
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(
QtWidgets.QHeaderView.ResizeMode.Stretch
)
@@ -214,13 +218,14 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparate.doubleClicked.connect(self.load_app_data)
self.load_app.hide()
print(f"user:{self.active_user}")
userrole = self.db.get_role(self.active_user)
userrole = self.db.getRole(self.active_user)
if userrole == "admin":
self.tabWidget.setTabVisible(2, True)
else:
self.tabWidget.setTabVisible(2, False)
# self.update_app_media_list()
self.populate_prof_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
self.drpdwn_prof_name.currentIndexChanged.connect(self.set_prof_data)
@@ -263,8 +268,7 @@ class Ui(Ui_Semesterapparat):
self.validate_thread.start()
# get all current apparats and cache them in a list
self.apparats = self.db.get_all_apparts(deleted=0)
print(self.apparats)
self.apparats = self.db.getAllAparats(deleted=0)
self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True)
for apparat in self.apparats:
@@ -297,6 +301,11 @@ class Ui(Ui_Semesterapparat):
self.update_user.clicked.connect(self.update_user_data)
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):
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}
ic(params)
retdata = self.db.search_book(params)
retdata = self.db.searchBook(params)
if retdata == None:
return
for book in retdata:
ic(book)
self.book_search_result.insertRow(0)
self.book_search_result.setItem(0,0,QtWidgets.QTableWidgetItem(book[0].title))
self.book_search_result.setItem(0,1,QtWidgets.QTableWidgetItem(book[0].signature))
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):
@@ -332,7 +342,7 @@ class Ui(Ui_Semesterapparat):
fullname = name.replace(",","")
print(fullname,name)
#get the data for the selected member
data = self.db.faculty_data(fullname)
data = self.db.getProfByName(fullname)
#set the data
print(data)
if data == None:
@@ -358,12 +368,12 @@ class Ui(Ui_Semesterapparat):
username = self.user_create_frame_username.text()
password = self.user_create_frame_password.text()
role = self.user_frame_userrole.currentText()
if self.db.check_username(username):
if self.db.checkUsername(username):
ic("username already exists")
# self.user_create_frame_error.setText("Der Nutzername ist bereits vergeben")#TODO: implement error message
return
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_password.clear()
self.user_frame_userrole.setCurrentText("")
@@ -372,7 +382,7 @@ class Ui(Ui_Semesterapparat):
def delete_user(self):
if self.user_delete_confirm.isChecked():
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_confirm.setChecked(False)
else:
@@ -392,7 +402,7 @@ class Ui(Ui_Semesterapparat):
}
data = {key: value for key, value in data.items() if value is not None}
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_new_password.clear()
self.user_edit_frame_role_select.setCurrentText("")
@@ -408,9 +418,9 @@ class Ui(Ui_Semesterapparat):
if fname != "" and lname != "":
return f"{lname} {fname}"
#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
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]
oldlname = data[2]
@@ -432,7 +442,7 @@ class Ui(Ui_Semesterapparat):
"telnr":telnr,
}
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.edit_faculty_member_new_title.setCurrentText("")
self.edit_faculty_member_new_surname.clear()
@@ -448,11 +458,11 @@ class Ui(Ui_Semesterapparat):
def admin_action_changed(self):
action = self.select_action_box.currentText()
roles = self.db.get_roles()
roles = self.db.getRoles()
roles = [role[0] for role in roles]
#remove duplicates
roles = list(dict.fromkeys(roles))
users = self.db.get_users()
users = self.db.getUsers()
users = [user[2] for user in users]
users.remove(self.active_user)
if "admin" in users:
@@ -485,7 +495,7 @@ class Ui(Ui_Semesterapparat):
return
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]
self.edit_faculty_member_select_member.clear()
self.edit_faculty_member_select_member.addItems(names)
@@ -535,7 +545,7 @@ class Ui(Ui_Semesterapparat):
self.statistics_table.currentRow(), 0
).text()
# 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
# split to two lists
created = {"Erstellt": data["created"]}
@@ -566,8 +576,8 @@ class Ui(Ui_Semesterapparat):
print(apparat)
#person selected case - open all apparats from this person in the tableWidget
self.tableWidget.setRowCount(0)
prof_id = self.db.get_prof_id(apparat.split("(")[0].strip())
apparats = self.db.get_apparats_by_prof(prof_id)
prof_id = self.db.getProfId(apparat.split("(")[0].strip())
apparats = self.db.getApparatsByProf(prof_id)
for app in apparats:
print(app)
#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.setCurrentText("")
#add custom vaules
appnrs = self.db.get_apparat_nrs()
appnrs = self.db.getUnavailableApparatNumbers()
apparats = natsorted(appnrs)
apparats = [str(apparat) for apparat in apparats]
self.box_appnrs.addItems(apparats)
persons = self.db.get_profs()
persons = self.db.getProfs()
self.box_person.addItems(
[f"{person[3]}, {person[2]}" for person in persons]
)
self.box_fach.addItems(subject[1] for subject in self.db.get_subjects())
semester = self.db.get_semester()
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.statistics_table.setRowCount(0)
#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)
# self.tabWidget_3.clear()
self.tabWidget_3.removeTab(1)
@@ -716,7 +726,7 @@ class Ui(Ui_Semesterapparat):
# delete all selected apparats
print(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
self.tab_changed()
self.btn_del_select_apparats.setEnabled(False)
@@ -729,7 +739,7 @@ class Ui(Ui_Semesterapparat):
"appnr": self.box_appnrs.currentText()
if self.box_appnrs.currentText() != ""
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() != ""
else None,
"fach": self.box_fach.currentText()
@@ -788,13 +798,23 @@ class Ui(Ui_Semesterapparat):
def populate_frame(self, appdata: ApparatData):
# populate the frame with the data from the database
ic(appdata)
self.drpdwn_app_nr.setCurrentText(str(appdata.appnr))
self.drpdwn_prof_title.setCurrentText(appdata.prof_title)
self.drpdwn_prof_name.setCurrentText(appdata.profname)
self.prof_title.setText(appdata.prof_title)
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_tel_nr.setText(appdata.prof_tel)
self.app_name.setText(appdata.appname)
print("changing dropdown app_fach from '' to ", 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:
self.sem_sommer.setChecked(
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.apparat_id_adis.setText(str(appdata.apparat_adis_id))
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):
appdata = ApparatData()
appdata.app_fach = self.app_fach.text()
appdata.app_fach = self.app_fach.currentText()
appdata.appname = self.app_name.text()
appdata.appnr = self.active_apparat()
appdata.dauerapp = self.check_eternal_app.isChecked()
appdata.prof_mail = self.prof_mail.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.semester = (
self.sem_sommer.text() + " " + self.sem_year.text()
@@ -835,7 +864,7 @@ class Ui(Ui_Semesterapparat):
self.add_files()
appdata.apparat_adis_id = self.apparat_id_adis.text()
self.db.update_apparat(appdata)
self.db.updateApparat(appdata)
self.update_app_media_list()
self.cancel_active_selection.click()
@@ -980,13 +1009,14 @@ class Ui(Ui_Semesterapparat):
self.prof_tel_nr.clear()
return
selected_prof = self.drpdwn_prof_name.currentText()
data = self.db.get_prof_data(selected_prof)
prof_title = data["prof_title"]
data = self.db.getProfData(selected_prof)
ic(data)
prof_title = data[2]
if prof_title == "None":
prof_title = "Kein Titel"
self.drpdwn_prof_title.setCurrentText(prof_title)
self.prof_tel_nr.setText(data["prof_tel"])
self.prof_mail.setText(data["prof_mail"])
self.prof_title.setText(prof_title)
self.prof_tel_nr.setText(data[1])
self.prof_mail.setText(data[0])
def get_index_of_value(self, table_widget, value):
for i in range(table_widget.rowCount()):
@@ -1010,21 +1040,20 @@ class Ui(Ui_Semesterapparat):
self.sem_year.setEnabled(False)
self.dokument_list.setRowCount(0)
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.btn_apparat_save.hide()
self.btn_reserve.show()
self.drpdwn_app_nr.setDisabled(True)
self.app_fach.setDisabled(True)
self.update_app_media_list()
self.update_documemt_list()
def update_documemt_list(self):
app_id = self.active_apparat()
prof_id = self.db.get_prof_id(
prof_id = self.db.getProfId(
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:
self.dokument_list.insertRow(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.drpdwn_app_nr.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.setCurrentText("")
if self.tableWidget_apparat_media.rowCount() > 0:
@@ -1063,13 +1092,13 @@ class Ui(Ui_Semesterapparat):
for item in self.frame.findChildren(QtWidgets.QLineEdit):
item.clear()
self.drpdwn_app_nr.clear()
self.drpdwn_prof_title.clear()
self.prof_title.clear()
self.drpdwn_prof_name.clear()
# set drop down menu for apparat numbers to only available numbers
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)
self.populate_prof_dropdown()
# self.horizontalLayout_6.show()
@@ -1112,9 +1141,9 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("Bitte mindestens ein Medium hinzufügen!")
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
if not self.db.app_exists(app_id):
if not self.db.checkApparatExists(app_id):
# create apparat
self.btn_save_apparat()
# 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()
# bd: BookData = BibTextTransformer(mode).get_data(webdata).return_data()
# 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
@@ -1166,9 +1195,9 @@ class Ui(Ui_Semesterapparat):
self.label_info.setText("Verfügbarkeit wird geprüft, bitte warten...")
self.label_info.show()
books = self.db.get_media(
books = self.db.getBooks(
self.active_apparat(),
self.db.get_prof_id(self.drpdwn_prof_name.currentText()),
self.db.getProfId(self.drpdwn_prof_name.currentText()),
del_state=0,
)
@@ -1190,14 +1219,15 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparat_media.setRowCount(0)
self.dokument_list.setRowCount(0)
self.frame.setEnabled(False)
self.app_fach.setCurrentText("")
for child in self.frame.findChildren(QtWidgets.QLineEdit):
child.clear()
def update_app_media_list(self):
deleted = 0 if not self.chkbx_show_del_media.isChecked() else 1
app_id = self.active_apparat()
prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText())
books: list[dict[int, BookData, int]] = self.db.get_media(
prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
books: list[dict[int, BookData, int]] = self.db.getBooks(
app_id, prof_id, deleted
)
@@ -1266,12 +1296,19 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparat_media.itemClicked.connect(self.open_link)
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
columnname = self.tableWidget_apparat_media.horizontalHeaderItem(
item.column()
).text()
if columnname == "Link":
QtGui.QDesktopServices.openUrl(QtCore.QUrl(item.text()))
__openLink(item.text())
else:
pass
@@ -1282,7 +1319,7 @@ class Ui(Ui_Semesterapparat):
clipboard.setText(text)
def populate_prof_dropdown(self):
profs = self.db.get_profs()
profs = self.db.getProfs()
# add empty entry to dropdown and set it as current
self.drpdwn_prof_name.addItem("Kein Name")
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()))
def open_document(self):
print("trying to open document:")
_selected_doc_name = ""
_selected_doc_filetype = ""
try:
@@ -1325,8 +1360,8 @@ class Ui(Ui_Semesterapparat):
except AttributeError:
self.confirm_popup("Bitte erst ein Dokument auswählen!")
return
print(_selected_doc_name, _selected_doc_filetype)
if not _selected_doc_location == "Database":
print("not in database")
path = Path(_selected_doc_location)
path = path + "/" + _selected_doc_name
if os.getenv("OS") == "Windows_NT":
@@ -1336,31 +1371,19 @@ class Ui(Ui_Semesterapparat):
path = path.resolve()
os.system(f"open {path}")
else:
print("in database")
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:
self.logger.log_exception(e)
path = config.save_path + _selected_doc_name
# if ~ in path, replace it with the home directory
if "~" in path:
path = path.replace("~", str(Path.home()))
path = Path(path)
if os.getenv("OS") == "Windows_NT":
path = path.resolve()
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))
print(e)
path = Path(file_loc)
if os.getenv("OS") == "Windows_NT":
path = path.resolve()
os.startfile(path)
else:
path = path.resolve()
os.system(f"open {path}")
def add_media_from_file(self):
def __open_dialog(signatures):
@@ -1408,7 +1431,7 @@ class Ui(Ui_Semesterapparat):
delete=False, suffix="." + file_type
)
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()
file = temp_file.name
@@ -1418,20 +1441,20 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("PDF Dateien werden nochnicht unterstützt!")
return
if file_type == "csv":
signatures = utils.csv_to_list(file)
signatures = csv_to_list(file)
data = __open_dialog(signatures)
# get the app_id and prof_id
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
for book in data:
if type(book) != BookData:
continue
self.db.add_medium(
self.db.addBookToDatabase(
bookdata=book, app_id=app_id, prof_id=prof_id
)
if file_type == "docx":
data = utils.word_docx_to_csv(file)
data = word_docx_to_csv(file)
signatures = [
i
for i in data["Standnummer"].values
@@ -1443,12 +1466,12 @@ class Ui(Ui_Semesterapparat):
return
# get the app_id and prof_id
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
for book in data:
if type(book) != BookData:
continue
self.db.add_medium(
self.db.addBookToDatabase(
bookdata=book, app_id=app_id, prof_id=prof_id
)
self.update_app_media_list()
@@ -1461,9 +1484,9 @@ class Ui(Ui_Semesterapparat):
"Bitte warten, bis alle Medien hinzugefügt wurden"
)
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
if not self.db.app_exists(app_id):
if not app_id in self.db.getUnavailableApparatNumbers():
# create apparat
self.btn_save_apparat()
if self.dokument_list.rowCount() == 0:
@@ -1490,13 +1513,13 @@ class Ui(Ui_Semesterapparat):
temp_file = tempfile.NamedTemporaryFile(
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()
file = temp_file.name
print(file)
if file_type == "pdf":
# Todo: implement parser here
self.confirm_popup("PDF Dateien werden nochnicht unterstützt!")
self.confirm_popup("PDF Dateien werden noch nicht unterstützt!")
return
if file_type == "csv":
signatures = csv_to_list(file)
@@ -1535,12 +1558,12 @@ class Ui(Ui_Semesterapparat):
def btn_save_apparat(self):
def __clear_fields():
self.drpdwn_app_nr.clear()
self.drpdwn_prof_title.clear()
self.prof_title.clear()
self.drpdwn_prof_name.clearMask()
self.app_name.clear()
self.prof_mail.clear()
self.prof_tel_nr.clear()
self.app_fach.clear()
self.app_fach.setCurrentText("")
self.app_name.clear()
self.sem_year.clear()
self.dokument_list.setRowCount(0)
@@ -1561,8 +1584,8 @@ class Ui(Ui_Semesterapparat):
appd.appnr = self.active_apparat()
appd.prof_title = (
None
if self.drpdwn_prof_title.currentText() == "Kein Titel"
else self.drpdwn_prof_title.currentText()
if self.prof_title.text() == ""
else self.prof_title.text()
)
appd.profname = self.drpdwn_prof_name.currentText()
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.prof_tel = self.prof_tel_nr.text()
appd.prof_mail = self.prof_mail.text()
app_fach = self.app_fach.currentText()
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.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()
self.add_files()
if not self.validate_fields():
pass
self.db.create_apparat(appd)
if self.dokument_list.rowCount() > 0:
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
self.apparats = list(set(self.apparats + appdata))
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.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):
# 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 __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"
self.tableWidget_apparate.insertRow(0)
@@ -1654,7 +1679,7 @@ class Ui(Ui_Semesterapparat):
0,
2,
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(
@@ -1668,10 +1693,18 @@ class Ui(Ui_Semesterapparat):
0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat))
)
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]}")
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):
menu = QtWidgets.QMenu()
extend_action = menu.addAction("Verlängern")
@@ -1687,6 +1720,7 @@ class Ui(Ui_Semesterapparat):
menu.exec(self.tableWidget_apparate.mapToGlobal(position))
def reminder(self):
self.logger.log_info("Opening reminder dialog")
dialog = QtWidgets.QDialog()
reminder = reminder_ui()
reminder.setupUi(dialog)
@@ -1694,7 +1728,7 @@ class Ui(Ui_Semesterapparat):
if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = reminder.return_message()
print(data)
self.db.add_message(
self.db.addMessage(
data,
self.active_user,
self.active_apparat if self.active_apparat() != "" else None,
@@ -1707,7 +1741,7 @@ class Ui(Ui_Semesterapparat):
# self.update_app_media_list()
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.calendarWidget.setMessages(messages)
self.calendarWidget.updateCells()
@@ -1722,12 +1756,12 @@ class Ui(Ui_Semesterapparat):
return
self.message_box.setText(message["message"])
self.line_app_info.setText(
message["apparatnr"] if message["apparatnr"] != None else "/"
message["appnr"] if message["appnr"] != None else "/"
)
def __delete_message():
message = messages[self.spin_select_message.value() - 1]
self.db.delete_message(message["id"])
self.db.deleteMessage(message["id"])
# remove message from list
messages.remove(message)
self.spin_select_message.setMaximum(len(messages))
@@ -1736,7 +1770,7 @@ class Ui(Ui_Semesterapparat):
selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd")
print(selected_date)
messages = self.db.get_messages(selected_date)
messages = self.db.getMessages(selected_date)
if messages == []:
self.message_frame.hide() if self.message_frame.isVisible() else None
return
@@ -1773,7 +1807,7 @@ class Ui(Ui_Semesterapparat):
def reload(self):
#create a new connection to the database, refresh table data and replace the old connection
self.db = Database()
self.apparats = self.db.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.tableWidget_apparate.setRowCount(0)
for apparat in self.apparats:
@@ -1793,12 +1827,12 @@ class Ui(Ui_Semesterapparat):
book = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1
).text()
book_id = self.db.request_medium(
book_id = self.db.getBookIdBasedOnSignature(
app_id=self.active_apparat(),
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()
bookedit = edit_bookdata_ui()
bookedit.setupUi(widget)
@@ -1809,7 +1843,7 @@ class Ui(Ui_Semesterapparat):
if widget.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = bookedit.get_data()
print(data)
self.db.update_bookdata(data, book_id)
self.db.updateBookdata(data, book_id)
# self.db.update_bookdata(data)
print("accepted")
self.update_app_media_list()
@@ -1824,17 +1858,17 @@ class Ui(Ui_Semesterapparat):
signature = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1
).text()
# bookdata= self.db.request_medium(selected_apparat_id,prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()),signature=signature)
book_id = self.db.request_medium(
# 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.getBookIdBasedOnSignature(
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,
)
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)
print(state)
if state == 1:
self.db.delete_medium(book_id)
self.db.deleteBook(book_id)
self.update_app_media_list()
pass
@@ -1862,7 +1896,7 @@ class Ui(Ui_Semesterapparat):
# apparat[7]=data["dauerapp"]
# break
# self.old_apparats = self.apparats
self.db.set_new_sem_date(
self.db.setNewSemesterDate(
selected_apparat_id, data["semester"], dauerapp=data["dauerapp"]
)
else:
@@ -1881,13 +1915,13 @@ class Ui(Ui_Semesterapparat):
).text()
general_data = {
"Appname": self.app_name.text(),
"AppSubject": self.app_fach.text(),
"AppSubject": self.app_fach.currentText(),
"appnr": active_apparat_id,
}
print(active_apparat_id)
mail_prev.appid = active_apparat_id
base_data = self.db.get_prof_data(id=active_apparat_id)
profname = self.db.get_prof_name_by_id(base_data["id"])
base_data = self.db.getProfData(id=active_apparat_id)
profname = self.db.getProfNameById(base_data["id"])
profname = profname.split(" ")
profname = f"{profname[1]} {profname[0]}"
pass_data = {
@@ -1908,7 +1942,7 @@ class Ui(Ui_Semesterapparat):
state = self.confirm_popup(message)
print(state)
if state == 1:
self.db.delete_apparat(
self.db.deleteApparat(
selected_apparat_id, self.generateSemester(today=True)
)
# delete the corresponding entry from self.apparats