290 lines
12 KiB
Python
290 lines
12 KiB
Python
from typing import List
|
|
|
|
from PySide6 import QtWidgets
|
|
from PySide6.QtCore import Qt
|
|
|
|
from src import Icon
|
|
from src.services.catalogue import Catalogue
|
|
from src.core.models import BookData
|
|
|
|
from .widget_sources.new_edition_check_book_ui import (
|
|
Ui_Dialog as Ui_NewEditionCheckBook,
|
|
)
|
|
from .widget_sources.new_edition_check_found_result_ui import (
|
|
Ui_Dialog as Ui_NewEditionCheckFoundResult,
|
|
)
|
|
from .widget_sources.new_edition_check_selector_ui import (
|
|
Ui_Dialog as Ui_NewEditionCheckSelector,
|
|
)
|
|
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):
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
self.setWindowTitle("Neuauflagen prüfen")
|
|
self.setWindowIcon(Icon("confirm_type").icon)
|
|
self.btn_apparat.clicked.connect(self.select_apparat)
|
|
self.btn_prof.clicked.connect(self.select_professor)
|
|
self.selection = None
|
|
|
|
def select_apparat(self):
|
|
self.selection = "apparat"
|
|
self.accept()
|
|
|
|
def select_professor(self):
|
|
self.selection = "professor"
|
|
self.accept()
|
|
|
|
|
|
class NewEditionCheckFoundResult(QtWidgets.QDialog, Ui_NewEditionCheckFoundResult):
|
|
def __init__(self, book: BookData, parent=None):
|
|
assert isinstance(book, BookData)
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
self.book = book
|
|
self.line_ppn.setText(self.book.ppn if self.book.ppn else "")
|
|
self.line_title.setText(self.book.title if self.book.title else "")
|
|
self.line_signature.setText(self.book.signature if self.book.signature else "")
|
|
self.line_edition.setText(self.book.edition if self.book.edition else "")
|
|
self.line_publisher.setText(self.book.publisher if self.book.publisher else "")
|
|
self.line_year.setText(self.book.year if self.book.year else "")
|
|
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"<a href='{link}'>{text}</a>"
|
|
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.signature is not None and self.book.signature != "":
|
|
self.in_library.setText(
|
|
f"Diese Neuauflage ist bereits in der Bibliothek vorhanden.\nStandort: {self.book.library_location}"
|
|
)
|
|
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.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}."
|
|
)
|
|
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"<a href='{LEHMANNS_LINK.format(self.line_isbn.text())}'>Lehmanns</a>"
|
|
)
|
|
|
|
|
|
class NewEditionCheckBook(QtWidgets.QDialog, Ui_NewEditionCheckBook):
|
|
def __init__(self, book: BookData, responses: List[BookData], parent=None):
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
self.book = book
|
|
self.accepted_books = []
|
|
self.responses = responses
|
|
author = self.book.author if self.book.author else cat.get_author(self.book.ppn)
|
|
if self.book.author is None and author is not None:
|
|
self.book.author = author
|
|
self.line_author.setText(author if author else "")
|
|
self.line_title.setText(self.book.title)
|
|
self.line_ppn.setText(self.book.ppn if self.book.ppn else "")
|
|
self.line_signature.setText(self.book.signature if self.book.signature else "")
|
|
self.line_edition.setText(self.book.edition if self.book.edition else "")
|
|
self.line_publisher.setText(self.book.publisher if self.book.publisher else "")
|
|
self.line_year.setText(self.book.year if self.book.year else "")
|
|
self.line_pages.setText(self.book.pages if self.book.pages else "")
|
|
self.line_isbn.setText(
|
|
", ".join(self.book.isbn)
|
|
if isinstance(self.book.isbn, list)
|
|
else self.book.isbn
|
|
)
|
|
|
|
for _ in range(self.stackedWidget.count()):
|
|
widget = self.stackedWidget.widget(0)
|
|
self.stackedWidget.removeWidget(widget)
|
|
widget.deleteLater()
|
|
for response in self.responses:
|
|
self.stackedWidget.addWidget(
|
|
NewEditionCheckFoundResult(parent=self, book=response)
|
|
)
|
|
self.label_book_index.setText(f"1 / {self.stackedWidget.count()}")
|
|
link = f"<a href='{self.book.link}'>Katalog</a>"
|
|
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"<a href='{LEHMANNS_LINK.format(isbn)}'>Lehmanns</a>"
|
|
)
|
|
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:
|
|
self.btn_next.hide()
|
|
self.btn_prev.hide()
|
|
|
|
def next(self):
|
|
index = self.stackedWidget.currentIndex()
|
|
if index < self.stackedWidget.count() - 1:
|
|
index += 1
|
|
self.stackedWidget.setCurrentIndex(index)
|
|
self.label_book_index.setText(f"{index + 1} / {self.stackedWidget.count()}")
|
|
self.btn_prev.show()
|
|
if index == self.stackedWidget.count() - 1:
|
|
self.btn_next.hide()
|
|
|
|
def previous(self):
|
|
index = self.stackedWidget.currentIndex()
|
|
if index > 0:
|
|
index -= 1
|
|
self.stackedWidget.setCurrentIndex(index)
|
|
self.label_book_index.setText(f"{index + 1} / {self.stackedWidget.count()}")
|
|
self.btn_next.show()
|
|
if index == 0:
|
|
self.btn_prev.hide()
|
|
if index < self.stackedWidget.count() - 1:
|
|
self.btn_next.show()
|
|
|
|
pass
|
|
|
|
|
|
class NewEditionChecker(QtWidgets.QDialog, Ui_NewEditionCheck):
|
|
def __init__(self, results, parent=None):
|
|
super().__init__(parent)
|
|
self.setupUi(self)
|
|
self.results = results
|
|
self.setWindowIcon(Icon("results").icon)
|
|
self.setWindowTitle(f"Neuauflagen prüfen ({len(self.results)})")
|
|
# remove pages from stacked widget
|
|
for _ in range(self.stackedWidget.count()):
|
|
widget = self.stackedWidget.widget(0)
|
|
self.stackedWidget.removeWidget(widget)
|
|
widget.deleteLater()
|
|
for resultset in self.results:
|
|
book, responses = resultset
|
|
# print(book, responses)
|
|
self.stackedWidget.addWidget(
|
|
NewEditionCheckBook(parent=self, book=book, responses=responses)
|
|
)
|
|
self.accepted_books = []
|
|
self.stackedWidget.setCurrentIndex(0)
|
|
self.progressBar.setMaximum(len(self.results))
|
|
self.progressBar.setValue(1)
|
|
self.btn_next.clicked.connect(self.next)
|
|
self.btn_prev.clicked.connect(self.previous)
|
|
self.btn_finish.hide()
|
|
self.btn_finish.clicked.connect(self.accept)
|
|
self.btn_prev.hide()
|
|
|
|
def next(self):
|
|
index = self.stackedWidget.currentIndex()
|
|
if index < self.stackedWidget.count() - 1:
|
|
index += 1
|
|
self.stackedWidget.setCurrentIndex(index)
|
|
self.progressBar.setValue(index + 1)
|
|
self.btn_prev.show()
|
|
if index == self.stackedWidget.count() - 1:
|
|
self.btn_next.hide()
|
|
self.btn_finish.show()
|
|
|
|
def previous(self):
|
|
index = self.stackedWidget.currentIndex()
|
|
if index > 0:
|
|
index -= 1
|
|
self.stackedWidget.setCurrentIndex(index)
|
|
self.progressBar.setValue(index + 1)
|
|
|
|
def accept(self) -> None:
|
|
# print("finished checking for new editions")
|
|
accepted_books = []
|
|
for i in range(self.stackedWidget.count()):
|
|
book_widget = self.stackedWidget.widget(i)
|
|
if isinstance(book_widget, NewEditionCheckBook):
|
|
for j in range(book_widget.stackedWidget.count()):
|
|
found_widget = book_widget.stackedWidget.widget(j)
|
|
if isinstance(found_widget, NewEditionCheckFoundResult):
|
|
if found_widget.checkBox.isChecked():
|
|
found_widget.book.old_book = book_widget.book
|
|
accepted_books.append(found_widget.book)
|
|
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()
|