110 lines
4.3 KiB
Python
110 lines
4.3 KiB
Python
from PySide6 import QtCore, QtWidgets
|
|
|
|
from src.services.catalogue import Catalogue
|
|
from src.database import Database
|
|
from src.ui.dialogs.mail import Mail_Dialog
|
|
|
|
from .dialog_sources.order_neweditions_ui import Ui_Dialog
|
|
|
|
|
|
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 not required here; using book.signature directly when needed
|
|
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()
|
|
checked = True if not book.signature else False
|
|
if book.library_location is not None:
|
|
checked = True if "hb" in book.library_location else checked
|
|
checkbox.setChecked(checked)
|
|
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))
|
|
isbn = (
|
|
book.isbn[0]
|
|
if isinstance(book.isbn, list) and len(book.isbn) > 0
|
|
else book.isbn
|
|
)
|
|
self.tableWidget.setItem(0, 3, QtWidgets.QTableWidgetItem(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})")
|
|
book.isbn = [book.isbn] if isinstance(book.isbn, str) else book.isbn
|
|
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()
|