UI: refactor mail template dialog for plaintext handling, improve logging, and update UI elements
This commit is contained in:
113
src/ui/dialogs/newEdition.py
Normal file
113
src/ui/dialogs/newEdition.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import sys
|
||||
|
||||
import loguru
|
||||
from PySide6 import QtCore, QtWidgets
|
||||
|
||||
from src import LOG_DIR
|
||||
from src.backend.database import Database
|
||||
from src.backend.catalogue import Catalogue
|
||||
|
||||
from src.ui.dialogs.mail import Mail_Dialog
|
||||
|
||||
from .dialog_sources.order_neweditions_ui import Ui_Dialog
|
||||
|
||||
log = loguru.logger
|
||||
log.remove()
|
||||
log.add(sys.stdout, level="INFO")
|
||||
log.add(f"{LOG_DIR}/application.log", rotation="1 MB", retention="10 days")
|
||||
|
||||
|
||||
class NewEditionDialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, app_id, mail_data):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.setWindowTitle("Neuauflagen bestellen")
|
||||
self.db = Database()
|
||||
self.catalogue = Catalogue()
|
||||
self.app_id = app_id
|
||||
self.mail_data = mail_data
|
||||
self.books = self.db.getNewEditionsByApparat(app_id)
|
||||
self.pushButton.clicked.connect(self.orderBooks)
|
||||
self.populateTable()
|
||||
|
||||
def populateTable(self):
|
||||
for book in self.books:
|
||||
signature = book.signature
|
||||
if signature is None or signature == "None":
|
||||
signature = self.catalogue.get_signature(book.ppn)
|
||||
link_label = QtWidgets.QLabel()
|
||||
link = (
|
||||
book.link
|
||||
if book.link != "SWB"
|
||||
else f"https://www.lehmanns.de/search/quick?mediatype_id=&q={book.isbn[0]}"
|
||||
)
|
||||
|
||||
link_label.setText(f'<a href="{link}">Lehmanns.de</a>')
|
||||
link_label.setOpenExternalLinks(True)
|
||||
link_label.setTextFormat(QtCore.Qt.TextFormat.RichText)
|
||||
link_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
|
||||
link_label.setTextInteractionFlags(
|
||||
QtCore.Qt.TextInteractionFlag.TextBrowserInteraction
|
||||
)
|
||||
self.tableWidget.insertRow(0)
|
||||
# first column is checkbox for ordering
|
||||
checkbox = QtWidgets.QCheckBox()
|
||||
|
||||
checkbox.setChecked(False)
|
||||
self.tableWidget.setCellWidget(0, 0, checkbox)
|
||||
self.tableWidget.setItem(
|
||||
0,
|
||||
1,
|
||||
QtWidgets.QTableWidgetItem(
|
||||
str(book.signature if book.signature else "")
|
||||
),
|
||||
)
|
||||
self.tableWidget.setItem(0, 2, QtWidgets.QTableWidgetItem(book.title))
|
||||
self.tableWidget.setItem(
|
||||
0, 3, QtWidgets.QTableWidgetItem(",".join(book.isbn))
|
||||
)
|
||||
self.tableWidget.setItem(0, 4, QtWidgets.QTableWidgetItem(book.author))
|
||||
self.tableWidget.setItem(0, 5, QtWidgets.QTableWidgetItem(book.edition))
|
||||
self.tableWidget.setItem(0, 6, QtWidgets.QTableWidgetItem(book.library_location))
|
||||
self.tableWidget.setCellWidget(0, 7, link_label)
|
||||
|
||||
def orderBooks(self):
|
||||
ordered_books = []
|
||||
for row in range(self.tableWidget.rowCount()):
|
||||
checkbox = self.tableWidget.cellWidget(row, 0)
|
||||
if checkbox.isChecked():
|
||||
book = self.books[row]
|
||||
book.link = (
|
||||
book.link
|
||||
if book.link != "SWB"
|
||||
else f"https://www.lehmanns.de/search/quick?mediatype_id=&q={book.isbn[0]}"
|
||||
)
|
||||
print(f"Bestelle Neuauflage für {book.title} ({book.edition})")
|
||||
ordered_books.append(book)
|
||||
# Process ordered_books as needed
|
||||
# editionId = self.db.getNewEditionId(book)
|
||||
# self.db.setOrdered(editionId)
|
||||
|
||||
self.mail = Mail_Dialog(
|
||||
app_id=self.mail_data.get("app_nr"),
|
||||
prof_name=self.mail_data.get("prof_name"),
|
||||
prof_mail=self.mail_data.get("prof_mail"),
|
||||
app_name=self.mail_data.get("app_name"),
|
||||
default_mail="Bitte um Bestellung",
|
||||
ordered_books=ordered_books,
|
||||
)
|
||||
self.mail.exec()
|
||||
|
||||
|
||||
def launch():
|
||||
app = QtWidgets.QApplication.instance()
|
||||
if app is None:
|
||||
app = QtWidgets.QApplication([])
|
||||
mail_data = {
|
||||
"prof_name": "Erwerbung",
|
||||
"prof_mail": "carola.wiestler@ph-freiburg.de",
|
||||
"app_nr": 131,
|
||||
"app_name": "Beratung und Teamarbeit",
|
||||
}
|
||||
dialog = NewEditionDialog(app_id=18, mail_data=mail_data)
|
||||
dialog.exec()
|
||||
Reference in New Issue
Block a user