minor and major reworks: rename swb to SRU, add a test for pdf parsing

major: rework mail to send mail as plaintext instead of html, preventing the bleed-in of html text
This commit is contained in:
2025-10-07 14:15:10 +02:00
parent 0df7fd9fe6
commit 06965db26a
25 changed files with 1174 additions and 303 deletions

View File

@@ -26,7 +26,6 @@ from src.backend import (
)
from src.backend.create_file import recreateFile
from src.backend.delete_temp_contents import delete_temp_contents as tempdelete
from src.backend.semester import Semester
from src.logic import (
APP_NRS,
Apparat,
@@ -34,7 +33,9 @@ from src.logic import (
BookData,
Prof,
SemapDocument,
Semester,
csv_to_list,
eml_to_semap,
pdf_to_semap,
word_to_semap,
)
@@ -207,6 +208,7 @@ class Ui(QtWidgets.QMainWindow, Ui_Semesterapparat):
self.progressBar.setMinimum(0)
self.avail_status.hide()
self.chkbx_show_del_media.hide()
self.chkbx_show_only_wit_neweditions.hide()
self.automation_add_selected_books.hide()
# self.btn_del_select_apparats.setEnabled(False)
@@ -896,7 +898,7 @@ class Ui(QtWidgets.QMainWindow, Ui_Semesterapparat):
)
# thread = QThread()
appnumber = self.active_apparat
appnumber = self.drpdwn_app_nr.currentText()
# #log.debug(links)
self.availChecker = AvailChecker(links, appnumber, books=books)
# availcheck.moveToThread(thread)
@@ -939,16 +941,14 @@ class Ui(QtWidgets.QMainWindow, Ui_Semesterapparat):
self.validate_semester()
def update_app_media_list(self):
deleted = 0 if not self.chkbx_show_del_media.isChecked() else 1
app_id = self.db.getId(self.app_name.text())
prof_id = self.db.getProfId(self.profdata)
books: list[dict[int, BookData, int]] = self.db.getBooks(
app_id, prof_id, deleted
)
books: list[dict[int, BookData, int]] = self.db.getBooks(app_id, prof_id, 0)
# # #log.debug(books)
# take the dataclass from the tuple
# booklist:list[BookData]=[book[0] for book in books]
self.tableWidget_apparat_media.clearContents()
self.tableWidget_apparat_media.setRowCount(0)
for book in books:
book["id"]
@@ -1198,6 +1198,8 @@ class Ui(QtWidgets.QMainWindow, Ui_Semesterapparat):
self.db.addBookToDatabase(
bookdata=book, app_id=app_id, prof_id=prof_id
)
if file_type == "eml":
data = eml_to_semap(file)
self.update_app_media_list()
# #log.debug(len(signatures))
@@ -1590,8 +1592,8 @@ class Ui(QtWidgets.QMainWindow, Ui_Semesterapparat):
mail_data = {
"prof_name": "Erwerbung",
"prof_mail": "erw@ph-freiburg.de",
"app_id": app_nr,
"app_name": self.db.getApparatName(app_id, prof_id),
"app_nr": app_nr,
"app_name": self.db.getApparatName(app_nr, prof_id),
}
orderDialog = NewEditionDialog(app_id, mail_data)
orderDialog.exec()
@@ -1672,12 +1674,13 @@ WHERE m.id = ?""",
newEditionChecker.exec()
accepted_books = newEditionChecker.accepted_books
print(accepted_books)
if accepted_books == []:
return
for book in accepted_books:
oldBookId = self.db.getBookIdByPPN(book.old_book.ppn)
apparats_id = self.db.getId(
self.db.getApparatNameByAppNr(book.old_book.library_location)
)
self.db.insertNewEdition(book, oldBookId, apparats_id)
pass
@@ -1763,11 +1766,17 @@ WHERE m.id = ?""",
apparat_add_action = QtGui.QAction("Zum Apparat hinzufügen")
apparat_move_action = QtGui.QAction("In Apparat verschieben")
apparat_copy_action = QtGui.QAction("In Apparat kopieren")
replace_old_editions = QtGui.QAction("Neuauflagen ersetzen")
apparatmenu = menu.addMenu("Apparate")
generalmenu = menu.addMenu("Allgemeines")
apparatmenu.addActions( # type: ignore
[apparat_add_action, apparat_copy_action, apparat_move_action]
[
apparat_add_action,
apparat_copy_action,
apparat_move_action,
replace_old_editions,
]
)
generalmenu.addActions([edit_action, delete_action, update_data_action]) # type: ignore
# disable apparat_add_action
@@ -1778,8 +1787,37 @@ WHERE m.id = ?""",
apparat_copy_action.triggered.connect(self.copy_to_apparat) # type: ignore
apparat_move_action.triggered.connect(self.move_to_apparat) # type: ignore
update_data_action.triggered.connect(self.update_data) # type: ignore
replace_old_editions.triggered.connect(self.replace_old_edition) # type: ignore
menu.exec(self.tableWidget_apparat_media.mapToGlobal(position)) # type: ignore
def replace_old_edition(self):
# open dialog
dialog = QtWidgets.QDialog()
dialog.setWindowTitle("Neuauflagen:")
layout = QtWidgets.QVBoxLayout()
label = QtWidgets.QLabel("Folgende Medien haben Neuauflagen:")
layout.addWidget(label)
table = QtWidgets.QTableWidget()
table.setColumnCount(4)
table.setHorizontalHeaderLabels(["Titel", "Auflage", "Signatur", "Neues Werk"])
table.horizontalHeader().setStretchLastSection(True)
new_editions = self.db.getBooksWithNewEditions(
self.active_apparat,
)
for book in new_editions:
table.insertRow(0)
table.setItem(0, 0, QtWidgets.QTableWidgetItem(book[0].title))
table.setItem(0, 1, QtWidgets.QTableWidgetItem(str(book[0].edition)))
table.setItem(0, 2, QtWidgets.QTableWidgetItem(book[0].signature))
new_ed_data = (
f"{book[1].title} (Auflage {book[1].edition}, {book[1].signature})"
)
table.setItem(0, 3, QtWidgets.QTableWidgetItem(new_ed_data))
layout.addWidget(table)
dialog.setLayout(layout)
dialog.exec()
def update_data(self):
signatures = [
self.tableWidget_apparat_media.item(row, 1).text()