fix broken files after faulty update
This commit is contained in:
@@ -7,16 +7,15 @@ import tempfile
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
|
||||
from icecream import ic
|
||||
from natsort import natsorted
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from PyQt6.QtCore import QThread
|
||||
from PyQt6.QtGui import QRegularExpressionValidator
|
||||
|
||||
from src import Icon, settings
|
||||
from src import Icon, settings, logger
|
||||
from src.backend import (
|
||||
Database,
|
||||
generateSemesterByDate,
|
||||
Semester,
|
||||
recreateFile,
|
||||
tempdelete,
|
||||
)
|
||||
@@ -27,9 +26,10 @@ from src.logic import (
|
||||
AvailChecker,
|
||||
BookData,
|
||||
BookGrabber,
|
||||
MyLogger,
|
||||
csv_to_list,
|
||||
word_docx_to_csv,
|
||||
Prof,
|
||||
Apparat,
|
||||
)
|
||||
from src.ui import (
|
||||
About,
|
||||
@@ -50,7 +50,7 @@ from src.ui import (
|
||||
ElsaDialog,
|
||||
UserCreate,
|
||||
EditUser,
|
||||
EditProf
|
||||
EditProf,
|
||||
)
|
||||
from src.utils import SemesterDocument
|
||||
|
||||
@@ -60,8 +60,7 @@ valid_input = (0, 0, 0, 0, 0, 0)
|
||||
class Ui(Ui_Semesterapparat):
|
||||
# use the Ui_MainWindow class from mainwindow.py
|
||||
def __init__(self, MainWindow, username: str) -> None:
|
||||
self.logger = MyLogger("Ui")
|
||||
self.logger.log_info("Starting Semesterapparatsmanagement")
|
||||
logger.info("Starting Semesterapparatsmanagement")
|
||||
super().__init__()
|
||||
self.active_user = username
|
||||
self.setupUi(MainWindow)
|
||||
@@ -172,7 +171,6 @@ class Ui(Ui_Semesterapparat):
|
||||
self.app_group_box.setEnabled(False)
|
||||
self.line_2.hide()
|
||||
self.progress_label.hide()
|
||||
# self.message_frame.hide()
|
||||
self.btn_reserve.hide()
|
||||
self.label_20.hide()
|
||||
self.line_3.hide()
|
||||
@@ -247,7 +245,7 @@ class Ui(Ui_Semesterapparat):
|
||||
apps.append(data)
|
||||
print(apps)
|
||||
doc = SemesterDocument(
|
||||
semester=self.generateSemester(today=True),
|
||||
semester=Semester(),
|
||||
filename="Semesterapparate",
|
||||
apparats=apps,
|
||||
)
|
||||
@@ -372,14 +370,12 @@ class Ui(Ui_Semesterapparat):
|
||||
"""Generates the current semester.
|
||||
|
||||
Args:
|
||||
-----
|
||||
today (bool, optional): If True, the current semester is generated. Defaults to False.
|
||||
Returns:
|
||||
--------
|
||||
str: The current semester
|
||||
"""
|
||||
if today:
|
||||
return generateSemesterByDate()
|
||||
return Semester()
|
||||
currentYear = self.sem_year.text()
|
||||
currentYear = int(currentYear[-2:])
|
||||
|
||||
@@ -387,7 +383,7 @@ class Ui(Ui_Semesterapparat):
|
||||
if semester == "SoSe":
|
||||
return "SoSe " + str(currentYear)
|
||||
else:
|
||||
return f"WiSe {currentYear}/{currentYear+1}"
|
||||
return f"WiSe {currentYear}/{currentYear + 1}"
|
||||
|
||||
def open_apparat(self, apparat):
|
||||
if self.load_app_data(apparat):
|
||||
@@ -402,41 +398,29 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
def populate_frame(self, appdata: ApparatData):
|
||||
# populate the frame with the data from the database
|
||||
self.drpdwn_app_nr.setCurrentText(str(appdata.appnr))
|
||||
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_app_nr.setCurrentText(str(appdata.apparat.appnr))
|
||||
self.prof_title.setText(appdata.prof.title)
|
||||
prof_name = appdata.prof.name(True)
|
||||
|
||||
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)
|
||||
self.prof_mail.setText(appdata.prof.mail)
|
||||
self.prof_tel_nr.setText(appdata.prof.telnr)
|
||||
self.app_name.setText(appdata.apparat.name)
|
||||
# print("changing dropdown app_fach from '' to ", appdata.app_fach)
|
||||
self.app_fach.setCurrentText(appdata.app_fach)
|
||||
self.app_fach.setCurrentText(appdata.apparat.subject)
|
||||
# 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
|
||||
)
|
||||
self.sem_winter.setChecked(
|
||||
True if appdata.semester.split(" ")[0] == "WiSe" else False
|
||||
)
|
||||
self.sem_year.setText(appdata.semester.split(" ")[1])
|
||||
else:
|
||||
self.sem_sommer.setChecked(
|
||||
True if appdata.erstellsemester.split(" ")[0] == "SoSe" else False
|
||||
)
|
||||
self.sem_winter.setChecked(
|
||||
True if appdata.erstellsemester.split(" ")[0] == "WiSe" else False
|
||||
)
|
||||
self.sem_year.setText(appdata.erstellsemester.split(" ")[1])
|
||||
self.check_eternal_app.setChecked(appdata.dauerapp)
|
||||
self.prof_id_adis.setText(str(appdata.prof_adis_id))
|
||||
self.apparat_id_adis.setText(str(appdata.apparat_adis_id))
|
||||
self.sem_year.setText(appdata.apparat.get_semester.split(" ")[1])
|
||||
match appdata.apparat.get_semester.split(" ")[0]:
|
||||
case "SoSe":
|
||||
self.sem_sommer.setChecked(True)
|
||||
self.sem_winter.setChecked(False)
|
||||
case "WiSe":
|
||||
self.sem_sommer.setChecked(False)
|
||||
self.sem_winter.setChecked(True)
|
||||
|
||||
self.check_eternal_app.setChecked(appdata.apparat.eternal)
|
||||
self.prof_id_adis.setText(str(appdata.apparat.prof_id_adis))
|
||||
self.apparat_id_adis.setText(str(appdata.apparat.apparat_id_adis))
|
||||
self.app_group_box.setEnabled(True)
|
||||
self.validateLoadedData()
|
||||
|
||||
@@ -449,25 +433,26 @@ class Ui(Ui_Semesterapparat):
|
||||
self.validate_semester()
|
||||
|
||||
def update_apparat(self):
|
||||
appdata = ApparatData()
|
||||
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.prof_title.text()
|
||||
appdata.profname = self.drpdwn_prof_name.currentText()
|
||||
appdata.semester = (
|
||||
prof = Prof()
|
||||
app = Apparat()
|
||||
app.subject = self.app_fach.currentText()
|
||||
app.name = self.app_name.text()
|
||||
app.appnr = self.active_apparat
|
||||
app.eternal = self.check_eternal_app.isChecked()
|
||||
prof.mail = self.prof_mail.text()
|
||||
prof.telnr = self.prof_tel_nr.text()
|
||||
prof.title = self.prof_title.text()
|
||||
prof.fullname = self.drpdwn_prof_name.currentText().replace(",", "")
|
||||
app.created_semester = (
|
||||
self.sem_sommer.text() + " " + self.sem_year.text()
|
||||
if self.sem_sommer.isChecked()
|
||||
else self.sem_winter.text() + " " + self.sem_year.text()
|
||||
)
|
||||
appdata.prof_adis_id = self.prof_id_adis.text()
|
||||
prof_id = self.db.getProfByName(appdata.prof_details.fullname).id
|
||||
app.prof_id_adis = self.prof_id_adis.text()
|
||||
prof_id = self.db.getProfByName(prof.fullname).id
|
||||
self.add_files(prof_id)
|
||||
appdata.apparat_adis_id = self.apparat_id_adis.text()
|
||||
|
||||
app.apparat_id_adis = self.apparat_id_adis.text()
|
||||
appdata = ApparatData(prof=prof, apparat=app)
|
||||
self.db.updateApparat(appdata)
|
||||
|
||||
self.update_app_media_list()
|
||||
@@ -597,7 +582,7 @@ class Ui(Ui_Semesterapparat):
|
||||
return
|
||||
selected_prof = self.drpdwn_prof_name.currentText()
|
||||
data = self.db.getProfData(selected_prof)
|
||||
# ic(data)
|
||||
# logger.debug(data)
|
||||
prof_title = data.title
|
||||
if prof_title == "None":
|
||||
prof_title = "Kein Titel"
|
||||
@@ -701,13 +686,13 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
def update_progress_label(self, curr, total):
|
||||
text = f"Medium {curr}/{total}"
|
||||
self.logger.log_info(text)
|
||||
logger.info(text)
|
||||
self.progress_label.setText(text)
|
||||
# update tableWidget_apparat_media
|
||||
self.update_app_media_list()
|
||||
|
||||
def hide_progress_label(self):
|
||||
self.logger.log_info("Finished adding media, hiding progress label")
|
||||
logger.info("Finished adding media, hiding progress label")
|
||||
self.progress_label.hide()
|
||||
self.progress_label.setText("Bitte warten...")
|
||||
self.line_2.hide()
|
||||
@@ -734,7 +719,7 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
app_id = self.active_apparat
|
||||
prof_id = self.db.getProfId(self.profdata)
|
||||
ic(prof_id)
|
||||
logger.debug(prof_id)
|
||||
# check if app_id is in database
|
||||
if self.db.checkApparatExistsById(app_id) is False:
|
||||
# create apparat
|
||||
@@ -1066,7 +1051,7 @@ class Ui(Ui_Semesterapparat):
|
||||
data = __open_dialog(signatures)
|
||||
# add the data to the database
|
||||
for book in data:
|
||||
if type(book) != BookData:
|
||||
if not isinstance(book, BookData):
|
||||
continue
|
||||
self.db.addBookToDatabase(
|
||||
bookdata=book, app_id=app_id, prof_id=prof_id
|
||||
@@ -1083,7 +1068,7 @@ class Ui(Ui_Semesterapparat):
|
||||
if data == []:
|
||||
return
|
||||
for book in data:
|
||||
if type(book) != BookData:
|
||||
if not isinstance(book, BookData):
|
||||
continue
|
||||
self.db.addBookToDatabase(
|
||||
bookdata=book, app_id=app_id, prof_id=prof_id
|
||||
@@ -1099,10 +1084,10 @@ class Ui(Ui_Semesterapparat):
|
||||
"Bitte warten, bis alle Medien hinzugefügt wurden"
|
||||
)
|
||||
app_id = self.active_apparat
|
||||
ic(self.profdata)
|
||||
logger.debug(self.profdata)
|
||||
prof_id = self.db.getProfId(self.profdata)
|
||||
|
||||
ic(prof_id)
|
||||
logger.debug(prof_id)
|
||||
# check if apparat in database
|
||||
|
||||
# if app_id not in database, create apparat
|
||||
@@ -1110,7 +1095,7 @@ class Ui(Ui_Semesterapparat):
|
||||
if not self.db.checkApparatExistsById(app_id):
|
||||
# create apparat
|
||||
# print("Creating apparat")
|
||||
if self.btn_save_apparat(False) == False:
|
||||
if not self.btn_save_apparat(False):
|
||||
return
|
||||
created = True
|
||||
if self.dokument_list.rowCount() == 0:
|
||||
@@ -1155,7 +1140,7 @@ class Ui(Ui_Semesterapparat):
|
||||
]
|
||||
|
||||
signatures = [i for i in signatures if i != ""]
|
||||
# ic(signatures)
|
||||
# logger.debug(signatures)
|
||||
# print("starting thread")
|
||||
if prof_id is None:
|
||||
prof_id = self.db.getProfId(self.profdata)
|
||||
@@ -1218,23 +1203,29 @@ class Ui(Ui_Semesterapparat):
|
||||
if not self.validate_fields():
|
||||
self.confirm_popup("Bitte alle Pflichtfelder ausfüllen!", title="Fehler")
|
||||
return False
|
||||
appd = ApparatData()
|
||||
appd.appnr = self.active_apparat
|
||||
appd.prof_title = self.prof_title.text()
|
||||
appd.profname = self.drpdwn_prof_name.currentText()
|
||||
appd.appname = self.app_name.text()
|
||||
appd.semester = self.generateSemester()
|
||||
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()
|
||||
appd.app_fach = self.app_fach.currentText()
|
||||
appd.erstellsemester = self.generateSemester()
|
||||
appd.deleted = 0
|
||||
appd.prof_adis_id = self.prof_id_adis.text()
|
||||
appd.apparat_adis_id = self.apparat_id_adis.text()
|
||||
prof = Prof(
|
||||
fullname=self.drpdwn_prof_name.currentText(),
|
||||
telnr=self.prof_tel_nr.text(),
|
||||
mail=self.prof_mail.text(),
|
||||
)
|
||||
prof.title = self.prof_title.text()
|
||||
apparat = Apparat(
|
||||
appnr=self.active_apparat,
|
||||
name=self.app_name.text(),
|
||||
created_semester=self.generateSemester(),
|
||||
eternal=1 if self.check_eternal_app.isChecked() else 0,
|
||||
subject=self.app_fach.currentText(),
|
||||
deleted=0,
|
||||
prof_id_adis=self.prof_id_adis.text(),
|
||||
apparat_id_adis=self.apparat_id_adis.text(),
|
||||
)
|
||||
|
||||
appd = ApparatData(prof=prof, apparat=apparat)
|
||||
|
||||
error = self.db.createApparat(appd)
|
||||
|
||||
if error:
|
||||
self.confirm_popup(error.__str__(), title="Fehler")
|
||||
return False
|
||||
if self.dokument_list.rowCount() > 0:
|
||||
self.add_files()
|
||||
if error is not None:
|
||||
@@ -1251,15 +1242,16 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
if self.check_send_mail.isChecked():
|
||||
self.contact_prof(
|
||||
apparat=appd.appnr,
|
||||
apparat=appd.apparat.appnr,
|
||||
mail="Information zum Semesterapparat",
|
||||
location="",
|
||||
pid=appd.profname,
|
||||
pid=appd.prof.fullname,
|
||||
)
|
||||
if clear_fields:
|
||||
# print("clearing fields")
|
||||
self.__clear_fields()
|
||||
return True
|
||||
|
||||
def send_mail_preview(self):
|
||||
pass
|
||||
|
||||
@@ -1270,12 +1262,12 @@ class Ui(Ui_Semesterapparat):
|
||||
@property
|
||||
def profdata(self):
|
||||
return {
|
||||
"title":self.prof_title.text(),
|
||||
"title": self.prof_title.text(),
|
||||
"profname": self.drpdwn_prof_name.currentText(),
|
||||
"prof_mail":self.prof_mail.text(),
|
||||
"prof_tel":self.prof_tel_nr.text()
|
||||
"prof_mail": self.prof_mail.text(),
|
||||
"prof_tel": self.prof_tel_nr.text(),
|
||||
}
|
||||
|
||||
|
||||
def add_files(self, prof_id=None):
|
||||
files = []
|
||||
for i in range(self.dokument_list.rowCount()):
|
||||
@@ -1304,12 +1296,13 @@ class Ui(Ui_Semesterapparat):
|
||||
|
||||
def update_apparat_list(self):
|
||||
self.tableWidget_apparate.setRowCount(0)
|
||||
|
||||
|
||||
for apparat in self.apparats:
|
||||
self.insert_apparat_into_table(apparat)
|
||||
logger.info("Inserted {} apparats into table".format(len(self.apparats)))
|
||||
|
||||
def insert_apparat_into_table(self, apparat):
|
||||
# ic(apparat)
|
||||
# logger.debug(apparat)
|
||||
def __dauer_check(apparat):
|
||||
return "Ja" if apparat[7] == 1 else "Nein"
|
||||
|
||||
@@ -1339,7 +1332,6 @@ class Ui(Ui_Semesterapparat):
|
||||
self.tableWidget_apparate.setItem(
|
||||
0, 5, QtWidgets.QTableWidgetItem(str(apparat[13]))
|
||||
)
|
||||
self.logger.log_info(f"Inserted apparat {apparat[4]}")
|
||||
|
||||
def open_context_menu(self, position):
|
||||
menu = QtWidgets.QMenu()
|
||||
@@ -1357,7 +1349,7 @@ class Ui(Ui_Semesterapparat):
|
||||
return
|
||||
pid = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 2)
|
||||
app_id = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 0)
|
||||
ic(pos, pid)
|
||||
logger.debug(pos, pid)
|
||||
extend_action.triggered.connect(self.extend_apparat)
|
||||
delete_action.triggered.connect(lambda: self.delete_apparat(pos))
|
||||
# pass pos to contact_prof
|
||||
@@ -1368,7 +1360,7 @@ class Ui(Ui_Semesterapparat):
|
||||
menu.exec(self.tableWidget_apparate.mapToGlobal(position))
|
||||
|
||||
def reminder(self):
|
||||
self.logger.log_info("Opening reminder dialog")
|
||||
logger.info("Opening reminder dialog")
|
||||
reminder = reminder_ui()
|
||||
reminder.exec()
|
||||
tableposition = self.tableWidget_apparate.currentRow()
|
||||
@@ -1385,17 +1377,17 @@ class Ui(Ui_Semesterapparat):
|
||||
self.calendarWidget.updateCells()
|
||||
# self.db.update_bookdata(data, book_id)
|
||||
# self.db.update_bookdata(data)
|
||||
self.logger.log_info("Commited message to database")
|
||||
logger.info("Commited message to database")
|
||||
# self.update_app_media_list()
|
||||
|
||||
def get_reminders(self):
|
||||
messages = self.db.getAllMessages()
|
||||
self.logger.log_info(f"Got {len(messages)} messages from database")
|
||||
logger.info(f"Got {len(messages)} messages from database")
|
||||
self.calendarWidget.setMessages(messages)
|
||||
self.calendarWidget.updateCells()
|
||||
|
||||
def open_reminder(self):
|
||||
if settings.mail.use_user_name == False:
|
||||
if not settings.mail.use_user_name:
|
||||
print("False")
|
||||
selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd")
|
||||
# # print(selected_date)
|
||||
@@ -1542,6 +1534,7 @@ class Ui(Ui_Semesterapparat):
|
||||
prof_id=self.db.getProfId(self.profdata),
|
||||
)
|
||||
print(medium.adis_idn, medium.signature)
|
||||
|
||||
def edit_medium(self):
|
||||
book = self.tableWidget_apparat_media.item(
|
||||
self.tableWidget_apparat_media.currentRow(), 1
|
||||
@@ -1592,7 +1585,7 @@ class Ui(Ui_Semesterapparat):
|
||||
prof_id=prof_id,
|
||||
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, title="Löschen?")
|
||||
# print(state)
|
||||
if state == 1:
|
||||
@@ -1642,12 +1635,12 @@ class Ui(Ui_Semesterapparat):
|
||||
return
|
||||
|
||||
def __get_table_data_field(self, table, row, column):
|
||||
ic(row, column)
|
||||
logger.debug(row, column)
|
||||
row = int(row)
|
||||
return table.item(row, column).text()
|
||||
|
||||
def __contact_dialog(self, apparat, location: tuple | str, mail=None, pid=""):
|
||||
ic(location, pid, apparat)
|
||||
logger.debug(location, pid, apparat)
|
||||
|
||||
active_apparat_id = (
|
||||
self.drpdwn_app_nr.currentText() if apparat is None else apparat
|
||||
@@ -1674,7 +1667,7 @@ class Ui(Ui_Semesterapparat):
|
||||
app_subject = self.app_fach.currentText()
|
||||
else:
|
||||
app_subject = self.db.getApparatData(active_apparat_id, app_name)
|
||||
app_subject = app_subject.app_fach
|
||||
app_subject = app_subject.apparat.subject
|
||||
# profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}"
|
||||
# print(pid)
|
||||
if prof_id:
|
||||
@@ -1696,8 +1689,8 @@ class Ui(Ui_Semesterapparat):
|
||||
self.mail_thread.show()
|
||||
|
||||
def contact_prof(self, apparat="", location="", mail="", pid=""):
|
||||
ic(apparat)
|
||||
ic(location)
|
||||
logger.debug(apparat)
|
||||
logger.debug(location)
|
||||
if self.active_apparat == "":
|
||||
if apparat is False:
|
||||
self.confirm_popup(
|
||||
@@ -1733,8 +1726,8 @@ class Ui(Ui_Semesterapparat):
|
||||
def launch_gui():
|
||||
# print("trying to login")
|
||||
# print("checking if database available")
|
||||
log = MyLogger("login")
|
||||
log.log_info("Starting login dialog")
|
||||
|
||||
logger.info("Starting login dialog")
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
login_dialog = QtWidgets.QDialog()
|
||||
ui = login_ui()
|
||||
|
||||
Reference in New Issue
Block a user