fix broken files after faulty update
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import os
|
||||
from natsort import natsorted
|
||||
from icecream import ic
|
||||
from .widget_sources.Ui_elsa_maindialog import Ui_Dialog
|
||||
from PyQt6 import QtCore, QtWidgets, QtGui
|
||||
from PyQt6.QtGui import QRegularExpressionValidator
|
||||
from PyQt6.QtCore import QDate
|
||||
from src import Icon
|
||||
from src.backend import recreateElsaFile, generateSemesterByDate, Database
|
||||
from src.logic import elsa_word_to_csv, MyLogger, Prof
|
||||
from src.logic.log import log
|
||||
from src import Icon, logger
|
||||
from src.backend import recreateElsaFile, Semester, Database
|
||||
from src.logic import elsa_word_to_csv, Prof
|
||||
from src.ui import popus_confirm
|
||||
from src.ui.dialogs import ElsaAddEntry
|
||||
from src.ui.widgets import FilePicker
|
||||
@@ -39,6 +37,23 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.quote_entry.clicked.connect(self.elsa_table_entry)
|
||||
self.quote_entry.setEnabled(False)
|
||||
self.newProf.hide()
|
||||
self.splitter = QtWidgets.QSplitter(QtCore.Qt.Orientation.Horizontal)
|
||||
self.splitter.addWidget(self.media_table)
|
||||
self.splitter.addWidget(self.statistics)
|
||||
self.results.layout().removeWidget(self.media_table)
|
||||
self.results.layout().removeWidget(self.statistics)
|
||||
self.results.layout().addWidget(self.splitter)
|
||||
self.elsa_statistics_table.setColumnCount(2)
|
||||
# set header to occupy the whole width and auto scale based on table width
|
||||
self.elsa_statistics_table.horizontalHeader().setStretchLastSection(True)
|
||||
self.elsa_statistics_table.horizontalHeader().setSectionResizeMode(
|
||||
QtWidgets.QHeaderView.ResizeMode.Stretch
|
||||
)
|
||||
# if table size gets smaller, set horitzontal headers text to be left aligned
|
||||
self.elsa_statistics_table.horizontalHeader().setDefaultAlignment(
|
||||
QtCore.Qt.AlignmentFlag.AlignLeft
|
||||
)
|
||||
# self.table_elsa_list.
|
||||
Icon("person", self.prof_icon)
|
||||
# validators
|
||||
# prof mail
|
||||
@@ -55,12 +70,12 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
)
|
||||
|
||||
##Variables
|
||||
self.logger = MyLogger("ElsaDialog")
|
||||
self.db = Database()
|
||||
self.graph_data = {"x": [generateSemesterByDate()], "y": [0]}
|
||||
self.graph_data = {"x": [Semester().value], "y": [0]}
|
||||
self.createProf = False
|
||||
self.profs = self.getProfs()
|
||||
|
||||
self.elsa_prof.addItems(self.getProfs())
|
||||
self.elsa_prof.addItems([prof[0] for prof in self.profs])
|
||||
self.elsa_prof.addItem("")
|
||||
self.elsa_prof.setCurrentText("")
|
||||
# implement a check for the prof name. if name is not in list and has schema of lastname, firstname, show newProf frame
|
||||
@@ -70,7 +85,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.newProf_title.textChanged.connect(self.checkProfData)
|
||||
|
||||
self.loadFrame()
|
||||
log.info("Elsa Dialog loaded")
|
||||
logger.info("Elsa Dialog loaded")
|
||||
# self.show()
|
||||
|
||||
def checkProfData(self):
|
||||
@@ -84,14 +99,20 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
):
|
||||
self.elsa_save.setEnabled(True)
|
||||
self.elsa_save.setToolTip("")
|
||||
self.newProf_mail.setToolTip("")
|
||||
self.newProf_telnr.setToolTip("")
|
||||
else:
|
||||
self.elsa_save.setEnabled(False)
|
||||
self.elsa_save.setToolTip("Bitte erst Daten eingeben")
|
||||
self.newProf_mail.setToolTip("Bitte geben Sie eine gültige E-Mail ein")
|
||||
self.newProf_telnr.setToolTip(
|
||||
"Bitte geben Sie eine gültige Telefonnummer ein"
|
||||
)
|
||||
|
||||
def checkProf(self):
|
||||
if (
|
||||
", " in self.elsa_prof.currentText()
|
||||
and self.elsa_prof.currentText() not in self.getProfs()
|
||||
and self.elsa_prof.currentText() not in [prof[0] for prof in self.profs]
|
||||
):
|
||||
self.newProf.show()
|
||||
self.elsa_save.setEnabled(False)
|
||||
@@ -105,7 +126,9 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
|
||||
def getProfs(self):
|
||||
profs = self.db.getProfs()
|
||||
profs = [f"{prof.lastname}, {prof.firstname}" for prof in profs]
|
||||
profs = [
|
||||
("{}, {}".format(prof.lastname, prof.firstname), prof.id) for prof in profs
|
||||
]
|
||||
|
||||
profs = list(set(profs))
|
||||
profs.sort()
|
||||
@@ -161,7 +184,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.elsa_date.setText(QDate.currentDate().toString("dd.MM.yyyy"))
|
||||
|
||||
def addSemester(self):
|
||||
self.elsa_semester.setText(generateSemesterByDate())
|
||||
self.elsa_semester.setText(Semester().value)
|
||||
|
||||
def update_elsa(self):
|
||||
prof = self.elsa_prof.currentText()
|
||||
@@ -205,11 +228,14 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
fullname=f"{prof.split(", ")[0]} {prof.split(", ")[1]}",
|
||||
)
|
||||
prof_id = self.db.getProfId(profdata)
|
||||
ic(profdata, prof_id)
|
||||
logger.debug(profdata, prof_id)
|
||||
|
||||
if prof_id is None:
|
||||
self.db.createProf(profdata)
|
||||
prof_id = self.db.getProfId(prof)
|
||||
self.profs.append(
|
||||
"f{}, {}".format(profdata.lastname, profdata.firstname), prof_id
|
||||
)
|
||||
elsa_id = self.db.createElsaApparat(
|
||||
date,
|
||||
prof_id,
|
||||
@@ -228,12 +254,12 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
files,
|
||||
elsa_id,
|
||||
)
|
||||
log.info("Stored {} files in the database", len(files))
|
||||
logger.info("Stored {} files in the database", len(files))
|
||||
self.cancel_elsa_creation()
|
||||
self.refresh_elsa_table()
|
||||
self.elsa_prof.setCurrentText("")
|
||||
self.quote_entry.setEnabled(False)
|
||||
log.info("Saved apparat to database, id {}", elsa_id)
|
||||
logger.info("Saved apparat to database, id {}", elsa_id)
|
||||
|
||||
def refresh_elsa_table(self):
|
||||
self.elsa_table.setRowCount(0)
|
||||
@@ -253,13 +279,13 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
|
||||
def open_elsa(self):
|
||||
prof = self.elsa_table.item(self.elsa_table.currentRow(), 0).text()
|
||||
print(prof)
|
||||
logger.info("prof", prof)
|
||||
date = self.elsa_table.item(self.elsa_table.currentRow(), 1).text()
|
||||
semester = self.elsa_table.item(self.elsa_table.currentRow(), 2).text()
|
||||
self.elsa_update.setEnabled(True)
|
||||
self.elsa_save.setEnabled(False)
|
||||
if self.elsa_prof.currentText() == prof and date == self.elsa_date.text():
|
||||
self.logger.log_info("Same prof, stopping")
|
||||
logger.debug("Same prof, stopping")
|
||||
return
|
||||
self.create_frame_elsa.setEnabled(True)
|
||||
self.dokument_list_elsa.setRowCount(0)
|
||||
@@ -269,24 +295,21 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
elsa_apparats = self.db.getElsaApparats()
|
||||
elsa_id = None
|
||||
for apparat in elsa_apparats:
|
||||
print(apparat)
|
||||
if (
|
||||
apparat[1] == date
|
||||
and apparat[2] == semester
|
||||
and apparat[3] == self.db.getProfId({"profname": prof})
|
||||
):
|
||||
elsa_id = apparat[0]
|
||||
# print(elsa_id)
|
||||
break
|
||||
self.elsa_date.setText(date)
|
||||
self.elsa_semester.setText(semester)
|
||||
self.elsa_prof.setCurrentText(prof)
|
||||
ic(elsa_id)
|
||||
logger.info("Elsa ID is {}", elsa_id)
|
||||
if elsa_id is None:
|
||||
return
|
||||
documents = self.db.getElsaFiles(elsa_id)
|
||||
for document in documents:
|
||||
# print(document)
|
||||
self.dokument_list_elsa.insertRow(0)
|
||||
self.dokument_list_elsa.setItem(
|
||||
0, 0, QtWidgets.QTableWidgetItem(document[0])
|
||||
@@ -340,13 +363,11 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.table_elsa_list.setItem(0, 11, QtWidgets.QTableWidgetItem(scan["type"]))
|
||||
|
||||
def addDokumentElsa(self):
|
||||
# print("Add document")
|
||||
picker = FilePicker()
|
||||
files = picker.pick_files()
|
||||
datalist = []
|
||||
for file in files:
|
||||
data = {}
|
||||
# print(file)
|
||||
filename = file.split("/")[-1]
|
||||
filetype = filename.split(".")[-1]
|
||||
self.dokument_list_elsa.insertRow(0)
|
||||
@@ -360,27 +381,6 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
data["path"] = file
|
||||
data["type"] = filetype
|
||||
datalist.append(data)
|
||||
# elsa_id = self.db.getElsaId(
|
||||
# self.elsa_prof.currentText(),
|
||||
# self.elsa_semester.text(),
|
||||
# self.elsa_date.text(),
|
||||
# )
|
||||
# # print(elsa_id)
|
||||
# if elsa_id is None:
|
||||
# # create elsa
|
||||
# self.db.createElsaApparat(
|
||||
# self.elsa_date.text(),
|
||||
# self.elsa_prof.currentText(),
|
||||
# self.elsa_semester.text(),
|
||||
# )
|
||||
# elsa_id = self.db.getElsaId(
|
||||
# self.elsa_prof.currentText(),
|
||||
# self.elsa_semester.text(),
|
||||
# self.elsa_date.text(),
|
||||
# )
|
||||
# self.db.insertElsaFile(datalist, elsa_id)
|
||||
# self.elsa_save.setEnabled(False)
|
||||
# self.refresh_elsa_table()
|
||||
|
||||
def parseDokumentElsa(self):
|
||||
if self.dokument_list_elsa.rowCount() == 0:
|
||||
@@ -389,7 +389,6 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
# get the file path of the selected file based on it's row
|
||||
row = self.dokument_list_elsa.currentRow()
|
||||
file = self.dokument_list_elsa.item(row, 3).text()
|
||||
# print(file)
|
||||
if file == "Database":
|
||||
filename = self.dokument_list_elsa.item(row, 0).text()
|
||||
filetype = self.dokument_list_elsa.item(row, 1).text()
|
||||
@@ -397,14 +396,13 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
file = recreateElsaFile(
|
||||
filename=filename, filetype=filetype, open=False
|
||||
)
|
||||
# print(file)
|
||||
data, _ = elsa_word_to_csv(file)
|
||||
elsa_id = self.db.getElsaId(
|
||||
self.db.getProfId(Prof(fullname=self.elsa_prof.currentText())),
|
||||
self.elsa_semester.text(),
|
||||
self.elsa_date.text(),
|
||||
)
|
||||
ic(
|
||||
logger.debug(
|
||||
elsa_id,
|
||||
self.elsa_prof.currentText(),
|
||||
self.elsa_semester.text(),
|
||||
@@ -441,14 +439,13 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
try:
|
||||
self.elsa_statistics.removeTab(1)
|
||||
except:
|
||||
self.logger.log_debug("No tab to remove")
|
||||
logger.debug("No tab to remove")
|
||||
self.elsa_table.setRowCount(0)
|
||||
elsa_apparats = self.db.getElsaApparats()
|
||||
elsa_apparats = natsorted(elsa_apparats, key=lambda x: x[2], reverse=True)
|
||||
# x = semester, y = number of apparats
|
||||
|
||||
for apparat in elsa_apparats:
|
||||
# print(apparat)
|
||||
data = self.insert_elsa_into_table(apparat)
|
||||
semester = data[0]
|
||||
number = data[1]
|
||||
@@ -466,7 +463,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
generateMissing,
|
||||
"Anzahl der Apparate",
|
||||
)
|
||||
ic(self.graph_data)
|
||||
logger.debug(self.graph_data)
|
||||
self.elsa_statistics_table.setRowCount(0)
|
||||
for i in range(len(self.graph_data["x"])):
|
||||
self.elsa_statistics_table.insertRow(0)
|
||||
@@ -479,7 +476,7 @@ class ElsaDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
self.elsa_statistics.addTab(graph, "Graph")
|
||||
|
||||
def launch():
|
||||
log.debug("Launching Elsa Dialog")
|
||||
logger.debug("Launching Elsa Dialog")
|
||||
app = QtWidgets.QApplication([])
|
||||
window = ElsaDialog()
|
||||
window.show()
|
||||
|
||||
Reference in New Issue
Block a user