diff --git a/src/ui/dialogs/newEdition.py b/src/ui/dialogs/newEdition.py index 56acf5e..44b920e 100644 --- a/src/ui/dialogs/newEdition.py +++ b/src/ui/dialogs/newEdition.py @@ -4,9 +4,8 @@ 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.backend.database import Database from src.ui.dialogs.mail import Mail_Dialog from .dialog_sources.order_neweditions_ui import Ui_Dialog @@ -33,8 +32,9 @@ class NewEditionDialog(QtWidgets.QDialog, Ui_Dialog): 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) + # if signature is None or signature == "None" and book.ppn is not None: + # signature = self.catalogue.get_signature(f"kid:{book.ppn}") + # book.signature = signature link_label = QtWidgets.QLabel() link = ( book.link @@ -52,8 +52,10 @@ class NewEditionDialog(QtWidgets.QDialog, Ui_Dialog): self.tableWidget.insertRow(0) # first column is checkbox for ordering checkbox = QtWidgets.QCheckBox() - - checkbox.setChecked(False) + 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, @@ -63,12 +65,17 @@ class NewEditionDialog(QtWidgets.QDialog, Ui_Dialog): ), ) self.tableWidget.setItem(0, 2, QtWidgets.QTableWidgetItem(book.title)) - self.tableWidget.setItem( - 0, 3, QtWidgets.QTableWidgetItem(",".join(book.isbn)) + 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.setItem( + 0, 6, QtWidgets.QTableWidgetItem(book.library_location) + ) self.tableWidget.setCellWidget(0, 7, link_label) def orderBooks(self): @@ -82,11 +89,12 @@ class NewEditionDialog(QtWidgets.QDialog, Ui_Dialog): 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})") + # 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) + # 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"), diff --git a/src/ui/widgets/new_edition_check.py b/src/ui/widgets/new_edition_check.py index 787c138..56a36b3 100644 --- a/src/ui/widgets/new_edition_check.py +++ b/src/ui/widgets/new_edition_check.py @@ -20,6 +20,8 @@ from .widget_sources.new_edition_check_ui import Ui_Dialog as Ui_NewEditionCheck cat = Catalogue() +LEHMANNS_LINK = "https://www.lehmanns.de/search/quick?mediatype_id=&q={}" + class NewEditionCheckSelector(QtWidgets.QDialog, Ui_NewEditionCheckSelector): def __init__(self, parent=None): @@ -55,41 +57,82 @@ class NewEditionCheckFoundResult(QtWidgets.QDialog, Ui_NewEditionCheckFoundResul self.line_pages.setText(self.book.pages if self.book.pages else "") self.line_author.setText(self.book.author if self.book.author else "") link = self.book.link if self.book.link else "" + text = "Lehmanns" if self.book.link else "Kein Link gefunden" if self.book.link != "SWB": - link = f"Lehmanns" + link = f"{text}" self.line_source.setText(link) self.line_source.setOpenExternalLinks(True) self.line_source.setTextFormat(Qt.TextFormat.RichText) self.line_source.setTextInteractionFlags( Qt.TextInteractionFlag.TextBrowserInteraction ) + self.line_isbn.textChanged.connect(self.update_book) + self.line_author.textChanged.connect(self.update_book) + self.line_title.textChanged.connect(self.update_book) + self.line_ppn.textChanged.connect(self.update_book) + self.line_signature.textChanged.connect(self.update_book) + self.line_edition.textChanged.connect(self.update_book) + self.line_publisher.textChanged.connect(self.update_book) + self.line_year.textChanged.connect(self.update_book) + self.line_pages.textChanged.connect(self.update_book) + self.line_isbn.setText( ", ".join(self.book.isbn) if isinstance(self.book.isbn, list) else self.book.isbn ) - if ( - self.book.link == "SWB" - and self.book.signature is not None - and self.book.signature != "" - ): + if self.book.signature is not None and self.book.signature != "": self.in_library.setText( - "Diese Neuauflage ist bereits in der Bibliothek vorhanden." + f"Diese Neuauflage ist bereits in der Bibliothek vorhanden.\nStandort: {self.book.library_location}" ) - self.book.link == f"https://www.lehmanns.de/search/quick?mediatype_id=&q={self.book.isbn[0]}" + isbn = ( + self.book.isbn[0] + if isinstance(self.book.isbn, list) and len(self.book.isbn) > 0 + else self.book.title + ) + self.book.link = LEHMANNS_LINK.format(self.line_isbn.text()) + if ( - self.book.link == "SWB" - and self.book.signature is not None + self.book.signature is not None and self.book.signature != "" and self.book.library_location not in (0, "0", None) ): self.in_library.setText( f"Diese Neuauflage ist bereits in der Bibliothek vorhanden, und an diesem Standort: {self.book.library_location}." ) - f"https://www.lehmanns.de/search/quick?mediatype_id=&q={self.book.isbn[0]}" + isbn = ( + str(self.book.isbn[0]) + if isinstance(self.book.isbn, list) + else str(self.book.isbn) + ) + self.book.link = LEHMANNS_LINK.format(isbn) pass + def update_book(self): + print("update book") + # for each line edit, get the value and assign it to the book on the corresponding attribute + for line_edit, attr in [ + (self.line_ppn, "ppn"), + (self.line_title, "title"), + (self.line_signature, "signature"), + (self.line_edition, "edition"), + (self.line_publisher, "publisher"), + (self.line_year, "year"), + (self.line_pages, "pages"), + (self.line_author, "author"), + (self.line_isbn, "isbn"), + ]: + value = line_edit.text() + if value == "": + value = None + setattr(self.book, attr, value) + print("set", attr, "to", value) + if attr == "isbn" and value is not None: + self.line_source.setText( + f"Lehmanns" + ) + class NewEditionCheckBook(QtWidgets.QDialog, Ui_NewEditionCheckBook): def __init__(self, book: BookData, responses: List[BookData], parent=None): @@ -124,6 +167,27 @@ class NewEditionCheckBook(QtWidgets.QDialog, Ui_NewEditionCheckBook): NewEditionCheckFoundResult(parent=self, book=response) ) self.label_book_index.setText(f"1 / {self.stackedWidget.count()}") + link = f"Katalog" + self.label_source_local.setText(link) + self.label_source_local.setOpenExternalLinks(True) + self.label_source_local.setTextFormat(Qt.TextFormat.RichText) + self.label_source_local.setTextInteractionFlags( + Qt.TextInteractionFlag.TextBrowserInteraction + ) + + isbn = ( + str(self.book.isbn[0]) + if isinstance(self.book.isbn, list) and len(self.book.isbn) > 0 + else f"{self.book.title}+{self.book.author}" + ) + self.label_source_external.setText( + f"Lehmanns" + ) + self.label_source_external.setOpenExternalLinks(True) + self.label_source_external.setTextFormat(Qt.TextFormat.RichText) + self.label_source_external.setTextInteractionFlags( + Qt.TextInteractionFlag.TextBrowserInteraction + ) self.btn_next.clicked.connect(self.next) self.btn_prev.clicked.connect(self.previous) if self.stackedWidget.count() <= 1: @@ -216,3 +280,10 @@ class NewEditionChecker(QtWidgets.QDialog, Ui_NewEditionCheck): super().accept() # print("accepted", len(accepted_books), "new editions") self.accepted_books = accepted_books + + +def launch(results: List[tuple[BookData, List[BookData]]]): + app = QtWidgets.QApplication([]) + widget = NewEditionChecker(results) + widget.show() + app.exec() diff --git a/src/ui/widgets/widget_sources/new_edition_check_book.ui b/src/ui/widgets/widget_sources/new_edition_check_book.ui index a6ffe71..9efbf17 100644 --- a/src/ui/widgets/widget_sources/new_edition_check_book.ui +++ b/src/ui/widgets/widget_sources/new_edition_check_book.ui @@ -149,6 +149,37 @@ + + + + + + + + + true + + + + + + + + + + true + + + + + + + + + Quelle + + + diff --git a/src/ui/widgets/widget_sources/new_edition_check_book_ui.py b/src/ui/widgets/widget_sources/new_edition_check_book_ui.py index ea7c457..d99db66 100644 --- a/src/ui/widgets/widget_sources/new_edition_check_book_ui.py +++ b/src/ui/widgets/widget_sources/new_edition_check_book_ui.py @@ -147,6 +147,28 @@ class Ui_Dialog(object): self.formLayout_2.setWidget(8, QFormLayout.ItemRole.FieldRole, self.line_isbn) + self.horizontalLayout_3 = QHBoxLayout() + self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") + self.label_source_local = QLabel(Dialog) + self.label_source_local.setObjectName(u"label_source_local") + self.label_source_local.setOpenExternalLinks(True) + + self.horizontalLayout_3.addWidget(self.label_source_local) + + self.label_source_external = QLabel(Dialog) + self.label_source_external.setObjectName(u"label_source_external") + self.label_source_external.setOpenExternalLinks(True) + + self.horizontalLayout_3.addWidget(self.label_source_external) + + + self.formLayout_2.setLayout(9, QFormLayout.ItemRole.FieldRole, self.horizontalLayout_3) + + self.label_12 = QLabel(Dialog) + self.label_12.setObjectName(u"label_12") + + self.formLayout_2.setWidget(9, QFormLayout.ItemRole.LabelRole, self.label_12) + self.gridLayout.addLayout(self.formLayout_2, 1, 0, 1, 1) @@ -196,6 +218,9 @@ class Ui_Dialog(object): self.label_7.setText(QCoreApplication.translate("Dialog", u"Seiten", None)) self.label_8.setText(QCoreApplication.translate("Dialog", u"Autor", None)) self.label_11.setText(QCoreApplication.translate("Dialog", u"ISBN", None)) + self.label_source_local.setText("") + self.label_source_external.setText("") + self.label_12.setText(QCoreApplication.translate("Dialog", u"Quelle", None)) self.btn_prev.setText(QCoreApplication.translate("Dialog", u"Previous", None)) self.btn_next.setText(QCoreApplication.translate("Dialog", u"Next", None)) # retranslateUi diff --git a/src/ui/widgets/widget_sources/new_edition_check_found_result.ui b/src/ui/widgets/widget_sources/new_edition_check_found_result.ui index b5abf1d..5f86f07 100644 --- a/src/ui/widgets/widget_sources/new_edition_check_found_result.ui +++ b/src/ui/widgets/widget_sources/new_edition_check_found_result.ui @@ -7,7 +7,7 @@ 0 0 400 - 312 + 346 @@ -113,12 +113,21 @@ + + Qt::NoFocus + Qt::PlainText + + true + + + Qt::LinksAccessibleByMouse + diff --git a/src/ui/widgets/widget_sources/new_edition_check_found_result_ui.py b/src/ui/widgets/widget_sources/new_edition_check_found_result_ui.py index 6290de1..8e2d17f 100644 --- a/src/ui/widgets/widget_sources/new_edition_check_found_result_ui.py +++ b/src/ui/widgets/widget_sources/new_edition_check_found_result_ui.py @@ -23,7 +23,7 @@ class Ui_Dialog(object): def setupUi(self, Dialog): if not Dialog.objectName(): Dialog.setObjectName(u"Dialog") - Dialog.resize(400, 312) + Dialog.resize(400, 346) self.formLayout = QFormLayout(Dialog) self.formLayout.setObjectName(u"formLayout") self.label = QLabel(Dialog) @@ -112,7 +112,10 @@ class Ui_Dialog(object): self.line_source = QLabel(Dialog) self.line_source.setObjectName(u"line_source") + self.line_source.setFocusPolicy(Qt.NoFocus) self.line_source.setTextFormat(Qt.PlainText) + self.line_source.setOpenExternalLinks(True) + self.line_source.setTextInteractionFlags(Qt.LinksAccessibleByMouse) self.formLayout.setWidget(10, QFormLayout.ItemRole.FieldRole, self.line_source)