Fix for loan list issue mentioned in #31

This commit is contained in:
Florian Bach 2022-10-08 18:03:45 +02:00
parent 79be3e3d87
commit 6c94e7237d
2 changed files with 21 additions and 10 deletions

View File

@ -1280,16 +1280,20 @@ class ConfigWidget(QWidget):
def show_rented_books(self): def show_rented_books(self):
self.delete_overdue_books_from_loan_list()
d = RentedBooksDialog(self) d = RentedBooksDialog(self)
d.exec_() d.exec_()
def delete_overdue_books_from_loan_list(self): class RentedBooksDialog(QDialog):
@staticmethod
def remove_overdue_books_from_list():
# Delete rented books that are overdue:
overdue_books = [] overdue_books = []
for book in self.deacsmprefs["list_of_rented_books"]: deacsmprefs = prefs.ACSMInput_Prefs()
for book in deacsmprefs["list_of_rented_books"]:
try: try:
book_time_stamp = book["validUntil"] book_time_stamp = book["validUntil"]
timestamp = datetime.datetime.strptime(book_time_stamp, "%Y-%m-%dT%H:%M:%SZ") timestamp = datetime.datetime.strptime(book_time_stamp, "%Y-%m-%dT%H:%M:%SZ")
@ -1303,24 +1307,29 @@ class ConfigWidget(QWidget):
overdue_books.append(book) overdue_books.append(book)
continue continue
templist = self.deacsmprefs["list_of_rented_books"] templist = deacsmprefs["list_of_rented_books"]
for book in overdue_books: for book in overdue_books:
templist.remove(book) templist.remove(book)
self.deacsmprefs.set("list_of_rented_books", templist) deacsmprefs.set("list_of_rented_books", templist)
self.deacsmprefs.writeprefs() deacsmprefs.writeprefs()
class RentedBooksDialog(QDialog):
def __init__(self, parent): def __init__(self, parent):
QDialog.__init__(self,parent) QDialog.__init__(self,parent)
self.parent = parent self.parent = parent
self.setWindowTitle("ACSM Input: Manage loaned Books")
self.setWindowTitle("ACSM Input: Manage loaned Books")
self.deacsmprefs = prefs.ACSMInput_Prefs() self.deacsmprefs = prefs.ACSMInput_Prefs()
# Delete rented books that are overdue:
RentedBooksDialog.remove_overdue_books_from_list()
# Start Qt Gui dialog layout # Start Qt Gui dialog layout
layout = QVBoxLayout(self) layout = QVBoxLayout(self)
self.setLayout(layout) self.setLayout(layout)

View File

@ -84,10 +84,12 @@ class ActualACSMInputGUIExtension(InterfaceAction):
from calibre.gui2 import info_dialog from calibre.gui2 import info_dialog
deacsmprefs = prefs.ACSMInput_Prefs() deacsmprefs = prefs.ACSMInput_Prefs()
from calibre_plugins.deacsm.config import RentedBooksDialog # type: ignore
RentedBooksDialog.remove_overdue_books_from_list()
if (len(deacsmprefs["list_of_rented_books"]) == 0): if (len(deacsmprefs["list_of_rented_books"]) == 0):
return info_dialog(None, "No loaned books", "You currently have no loaned books.", show=True, show_copy_button=False) return info_dialog(None, "No loaned books", "You currently have no loaned books.", show=True, show_copy_button=False)
from calibre_plugins.deacsm.config import RentedBooksDialog # type: ignore
d = RentedBooksDialog(self.gui) d = RentedBooksDialog(self.gui)
d.exec_() d.exec_()