update files, bring to latest code
This commit is contained in:
5
main.py
5
main.py
@@ -1,3 +1,4 @@
|
|||||||
hello_world = lambda: "Hello, World!"
|
from src.ui.main_ui import launch
|
||||||
|
|
||||||
print(hello_world())
|
if __name__ == "__main__":
|
||||||
|
launch()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
__help__ = "This package contains the logic of the application."
|
__help__ = "This package contains the logic of the application."
|
||||||
from .database import Database
|
from .database import Database
|
||||||
from .catalogue import Catalogue
|
from .catalogue import Catalogue
|
||||||
|
from .backup import Backup
|
||||||
@@ -3,7 +3,7 @@ from bs4 import BeautifulSoup
|
|||||||
from src import config
|
from src import config
|
||||||
from src.schemas import Book
|
from src.schemas import Book
|
||||||
|
|
||||||
URL = "https://rds.ibs-bw.de/phfreiburg/opac/RDSIndex/Search?lookfor={}+&type=AllFields&limit=10&sort=py+desc%2C+title"
|
URL = 'https://rds.ibs-bw.de/phfreiburg/opac/RDSIndex/Search?lookfor="{}"+&type=AllFields&limit=10&sort=py+desc%2C+title'
|
||||||
BASE = "https://rds.ibs-bw.de"
|
BASE = "https://rds.ibs-bw.de"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
from src import config
|
from src import config
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from src.schemas import USERS, MEDIA, LOANS, User, Book
|
from src.schemas import USERS, MEDIA, LOANS, User, Book
|
||||||
|
from src.utils.stringtodate import stringToDate
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, db_path: str = None):
|
def __init__(self, db_path: str = None):
|
||||||
@@ -143,6 +143,32 @@ class Database:
|
|||||||
self.close_connection(conn)
|
self.close_connection(conn)
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
def getMediaSimilarSignatureByID(self, media_id) -> list[Book]:
|
||||||
|
query = f"SELECT * FROM media WHERE id = '{media_id}'"
|
||||||
|
conn = self.connect()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
result = cursor.fetchone()
|
||||||
|
signature = result[1]
|
||||||
|
print(signature)
|
||||||
|
query = f"SELECT * FROM media WHERE signature LIKE '%{signature}%'"
|
||||||
|
cursor.execute(query)
|
||||||
|
result = cursor.fetchall()
|
||||||
|
|
||||||
|
self.close_connection(conn)
|
||||||
|
data = []
|
||||||
|
for res in result:
|
||||||
|
data.append(
|
||||||
|
Book(
|
||||||
|
signature=res[1],
|
||||||
|
isbn=res[2],
|
||||||
|
ppn=res[3],
|
||||||
|
title=res[4],
|
||||||
|
database_id=res[0],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
def getMedia(self, media_id):
|
def getMedia(self, media_id):
|
||||||
query = f"SELECT * FROM media WHERE id = '{media_id}'"
|
query = f"SELECT * FROM media WHERE id = '{media_id}'"
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
@@ -159,6 +185,25 @@ class Database:
|
|||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def getAllMedia(self, user_id):
|
||||||
|
# get all books that have the user id in the loans table
|
||||||
|
query = f"SELECT * FROM loans WHERE user_id = '{user_id}'"
|
||||||
|
conn = self.connect()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
result = cursor.fetchall()
|
||||||
|
self.close_connection(conn)
|
||||||
|
books = []
|
||||||
|
for res in result:
|
||||||
|
book = self.getMedia(res[2])
|
||||||
|
book.loan_from = res[3]
|
||||||
|
book.loan_to = res[4]
|
||||||
|
book.returned = res[5]
|
||||||
|
book.returned_date = res[6]
|
||||||
|
books.append(book)
|
||||||
|
print(book)
|
||||||
|
return books
|
||||||
|
|
||||||
def checkMediaExists(self, media):
|
def checkMediaExists(self, media):
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@@ -182,8 +227,8 @@ class Database:
|
|||||||
self.close_connection(conn)
|
self.close_connection(conn)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def returnMedia(self, media_id):
|
def returnMedia(self, media_id, returndate):
|
||||||
query = f"UPDATE loans SET returned = 1 WHERE media_id = '{media_id}'"
|
query = f"UPDATE loans SET returned = 1, returned_date = '{returndate}' WHERE media_id = '{media_id}' AND returned = 0"
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
@@ -222,3 +267,12 @@ class Database:
|
|||||||
self.close_connection(conn)
|
self.close_connection(conn)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
|
def extendLoanDuration(self, signature, newDate):
|
||||||
|
book_id = self.checkMediaExists(Book(signature=signature))
|
||||||
|
query = f"UPDATE loans SET return_date = '{newDate}' WHERE media_id = '{book_id[0]}' AND returned = 0"
|
||||||
|
conn = self.connect()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
self.close_connection(conn)
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ class Book:
|
|||||||
link: str | None = None
|
link: str | None = None
|
||||||
database_id: int | None = None
|
database_id: int | None = None
|
||||||
link: str | None = None
|
link: str | None = None
|
||||||
|
loan_from: str | None = None
|
||||||
|
loan_to: str | None = None
|
||||||
|
returned: int | None = None
|
||||||
|
returned_date: str | None = None
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ signature TEXT NOT NULL,
|
|||||||
isbn TEXT NOT NULL,
|
isbn TEXT NOT NULL,
|
||||||
ppn TEXT NOT NULL,
|
ppn TEXT NOT NULL,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
link TEXT NOT NULL,);
|
link TEXT NOT NULL);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
LOANS = """CREATE TABLE IF NOT EXISTS loans (
|
LOANS = """CREATE TABLE IF NOT EXISTS loans (
|
||||||
@@ -19,6 +19,7 @@ media_id INTEGER NOT NULL,
|
|||||||
loan_date TEXT NOT NULL,
|
loan_date TEXT NOT NULL,
|
||||||
return_date TEXT NOT NULL,
|
return_date TEXT NOT NULL,
|
||||||
returned INTEGER DEFAULT 0,
|
returned INTEGER DEFAULT 0,
|
||||||
|
returned_date TEXT,
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||||
FOREIGN KEY (media_id) REFERENCES media(id));
|
FOREIGN KEY (media_id) REFERENCES media(id));
|
||||||
"""
|
"""
|
||||||
|
|||||||
31
src/ui/extendLoan.py
Normal file
31
src/ui/extendLoan.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from .sources.Ui_dialog_extendLoanDuration import Ui_Dialog
|
||||||
|
from PyQt6 import QtWidgets, QtCore
|
||||||
|
|
||||||
|
|
||||||
|
class ExtendLoan(QtWidgets.QDialog, Ui_Dialog):
|
||||||
|
def __init__(self, user, media):
|
||||||
|
super(ExtendLoan, self).__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.user = user
|
||||||
|
self.media = media
|
||||||
|
self.currentDate = QtCore.QDate.currentDate().addDays(1)
|
||||||
|
self.extendDate = None
|
||||||
|
self.extenduntil.setMinimumDate(self.currentDate)
|
||||||
|
self.show()
|
||||||
|
self.buttonBox.accepted.connect(self.extendLoan)
|
||||||
|
|
||||||
|
def extendLoan(self):
|
||||||
|
print("Extend Loan")
|
||||||
|
selectedDate = self.extenduntil.selectedDate()
|
||||||
|
print(selectedDate)
|
||||||
|
self.extendDate = selectedDate
|
||||||
|
self.close()
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def launch(user, media):
|
||||||
|
import sys
|
||||||
|
|
||||||
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
window = ExtendLoan(user, media)
|
||||||
|
sys.exit(app.exec())
|
||||||
@@ -4,9 +4,10 @@ from .user import UserUI
|
|||||||
from .createUser import CreateUser
|
from .createUser import CreateUser
|
||||||
from .multiUserInfo import MultiUserFound
|
from .multiUserInfo import MultiUserFound
|
||||||
from .newentry import NewEntry
|
from .newentry import NewEntry
|
||||||
|
from .settings import Settings
|
||||||
from src import config
|
from src import config
|
||||||
from src.logic import Database, Catalogue, Backup
|
from src.logic import Database, Catalogue, Backup
|
||||||
from src.utils import stringToDate
|
from src.utils import stringToDate, Icon
|
||||||
from src.schemas import User, Book
|
from src.schemas import User, Book
|
||||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
import sys
|
import sys
|
||||||
@@ -18,6 +19,8 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(MainUI, self).__init__()
|
super(MainUI, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.setWindowTitle("Handbibliotheksleihsystem")
|
||||||
|
self.setWindowIcon(Icon("main").icon)
|
||||||
self.db = Database()
|
self.db = Database()
|
||||||
self.currentDate = QtCore.QDate.currentDate()
|
self.currentDate = QtCore.QDate.currentDate()
|
||||||
self.label_7.hide()
|
self.label_7.hide()
|
||||||
@@ -29,7 +32,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
# hotkeys
|
# hotkeys
|
||||||
self.actionRueckgabemodus.triggered.connect(self.changeMode)
|
self.actionRueckgabemodus.triggered.connect(self.changeMode)
|
||||||
self.actionNutzer.triggered.connect(self.showUser)
|
self.actionNutzer.triggered.connect(self.showUser)
|
||||||
|
self.actionEinstellungen.triggered.connect(self.showSettings)
|
||||||
#Buttons
|
#Buttons
|
||||||
self.btn_show_lentmedia.clicked.connect(self.showUser)
|
self.btn_show_lentmedia.clicked.connect(self.showUser)
|
||||||
|
|
||||||
@@ -40,7 +43,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.input_username.returnPressed.connect(
|
self.input_username.returnPressed.connect(
|
||||||
lambda: self.checkUser("username", self.input_username.text())
|
lambda: self.checkUser("username", self.input_username.text())
|
||||||
)
|
)
|
||||||
self.input_file_ident.returnPressed.connect(self.addMedia)
|
self.input_file_ident.returnPressed.connect(self.handleLineInput)
|
||||||
self.input_userno.setValidator(QtGui.QIntValidator())
|
self.input_userno.setValidator(QtGui.QIntValidator())
|
||||||
|
|
||||||
# TableWidget
|
# TableWidget
|
||||||
@@ -52,29 +55,29 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
def showSettings(self):
|
||||||
|
settings = Settings()
|
||||||
|
settings.exec()
|
||||||
|
|
||||||
def changeMode(self):
|
def changeMode(self):
|
||||||
current = self.mode.text()
|
self.mode.setText("Rückgabe")
|
||||||
if current == "Ausleihe":
|
self.input_username.clear()
|
||||||
self.mode.setText("Rückgabe")
|
self.input_userno.clear()
|
||||||
self.input_username.clear()
|
self.userdata.clear()
|
||||||
self.input_userno.clear()
|
self.btn_show_lentmedia.setText("")
|
||||||
self.userdata.clear()
|
self.input_file_ident.clear()
|
||||||
self.btn_show_lentmedia.setText("")
|
self.label_7.hide()
|
||||||
self.label_7.hide()
|
self.nextReturnDate.hide()
|
||||||
self.nextReturnDate.hide()
|
|
||||||
if current == "Rückgabe":
|
|
||||||
self.input_username.clear()
|
|
||||||
self.input_userno.clear()
|
|
||||||
self.userdata.clear()
|
|
||||||
self.mediaOverview.setRowCount(0)
|
|
||||||
self.btn_show_lentmedia.setText("")
|
|
||||||
self.input_file_ident.clear()
|
|
||||||
self.nextReturnDate.hide()
|
|
||||||
self.label_7.hide()
|
|
||||||
|
|
||||||
def showUser(self):
|
def showUser(self):
|
||||||
if self.activeUser is None:
|
if self.activeUser is None:
|
||||||
# create warning dialog
|
# create warning dialog
|
||||||
|
dialog = QtWidgets.QMessageBox()
|
||||||
|
dialog.setWindowTitle("Kein Nutzer ausgewählt")
|
||||||
|
dialog.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
||||||
|
dialog.setWindowIcon(Icon("warning").overwriteColor("#EA3323"))
|
||||||
|
dialog.setText("Kein Nutzer ausgewählt")
|
||||||
|
dialog.exec()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.user_ui = UserUI(
|
self.user_ui = UserUI(
|
||||||
@@ -123,7 +126,18 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def moveToLine(self, line):
|
def moveToLine(self, line):
|
||||||
line.setFocus()
|
line.setFocus()
|
||||||
|
|
||||||
|
def handleLineInput(self):
|
||||||
|
value = self.input_file_ident.text().strip()
|
||||||
|
if len(value) <= 2:
|
||||||
|
self.callShortcut(value)
|
||||||
|
else:
|
||||||
|
if self.mode.text() == "Rückgabe":
|
||||||
|
self.returnMedia(value)
|
||||||
|
else:
|
||||||
|
self.mediaAdd(value)
|
||||||
|
|
||||||
def mediaAdd(self, identifier):
|
def mediaAdd(self, identifier):
|
||||||
|
self.clearStatusTip
|
||||||
print("Adding Media", identifier)
|
print("Adding Media", identifier)
|
||||||
self.setStatusTip("")
|
self.setStatusTip("")
|
||||||
self.input_file_ident.clear()
|
self.input_file_ident.clear()
|
||||||
@@ -138,13 +152,33 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
if book_id:
|
if book_id:
|
||||||
if len(book_id) > 1:
|
if len(book_id) > 1:
|
||||||
print("Multiple Books found")
|
print("Multiple Books found")
|
||||||
|
# TODO: implement book selection dialog
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# check if book is already loaned
|
# check if book is already loaned
|
||||||
loaned = self.db.checkLoanState(book_id[0])
|
loaned = self.db.checkLoanState(book_id[0])
|
||||||
if loaned:
|
if loaned:
|
||||||
print("Book already loaned")
|
print("Book already loaned")
|
||||||
self.setStatusTip("Book already loaned")
|
self.setStatusTipMessage("Buch bereits entliehen")
|
||||||
|
# dialog with yes no to create new entry
|
||||||
|
dialog = QtWidgets.QMessageBox()
|
||||||
|
dialog.setText(
|
||||||
|
"Buch bereits entliehen, soll ein neues hinzugefügt werden?"
|
||||||
|
)
|
||||||
|
dialog.setStandardButtons(
|
||||||
|
QtWidgets.QMessageBox.StandardButton.Yes
|
||||||
|
| QtWidgets.QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
|
dialog.setDefaultButton(QtWidgets.QMessageBox.StandardButton.No)
|
||||||
|
dialog.exec()
|
||||||
|
result = dialog.result()
|
||||||
|
if result == QtWidgets.QMessageBox.StandardButton.No:
|
||||||
|
return
|
||||||
|
newentry = NewEntry([book_id[0]])
|
||||||
|
newentry.exec()
|
||||||
|
self.setStatusTipMessage("Neues Exemplar hinzugefügt")
|
||||||
|
created_ids = newentry.newIds
|
||||||
|
print(created_ids)
|
||||||
self.input_file_ident.setEnabled(True)
|
self.input_file_ident.setEnabled(True)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -189,14 +223,6 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
sysem_shortcuts = None
|
sysem_shortcuts = None
|
||||||
print(sysem_shortcuts)
|
print(sysem_shortcuts)
|
||||||
|
|
||||||
def addMedia(self):
|
|
||||||
mode = self.mode.text()
|
|
||||||
value = self.input_file_ident.text()
|
|
||||||
# if vaule is string, call shortcut, else mediaAdd
|
|
||||||
if mode == "Rückgabe":
|
|
||||||
self.returnMedia(value)
|
|
||||||
else:
|
|
||||||
self.lendMedia(value)
|
|
||||||
|
|
||||||
def returnMedia(self, identifier):
|
def returnMedia(self, identifier):
|
||||||
print("Returning Media", identifier)
|
print("Returning Media", identifier)
|
||||||
@@ -232,15 +258,12 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
print("Book not found")
|
print("Book not found")
|
||||||
|
|
||||||
def lendMedia(self, value):
|
def setStatusTipMessage(self, message):
|
||||||
value = value.strip()
|
self.setStatusTip(message)
|
||||||
if value.isnumeric():
|
|
||||||
self.mediaAdd(value)
|
@property
|
||||||
else:
|
def clearStatusTip(self):
|
||||||
if len(value) <= 2:
|
self.setStatusTip("")
|
||||||
self.callShortcut(value)
|
|
||||||
else:
|
|
||||||
self.mediaAdd(value)
|
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print("Exiting")
|
print("Exiting")
|
||||||
@@ -258,6 +281,6 @@ def exit_handler():
|
|||||||
def launch():
|
def launch():
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
main_ui = MainUI()
|
main_ui = MainUI()
|
||||||
atexit.register(exit_handler)
|
# atexit.register(exit_handler)
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
# sys.exit(app.exec())
|
# sys.exit(app.exec())
|
||||||
|
|||||||
@@ -2,18 +2,20 @@ from .sources.Ui_dialog_addNewTitleEntry import Ui_Dialog
|
|||||||
from PyQt6 import QtWidgets, QtCore, QtGui
|
from PyQt6 import QtWidgets, QtCore, QtGui
|
||||||
from src.logic import Database
|
from src.logic import Database
|
||||||
from src.schemas import Book
|
from src.schemas import Book
|
||||||
|
from src.utils import Icon
|
||||||
|
|
||||||
class NewEntry(QtWidgets.QDialog, Ui_Dialog):
|
class NewEntry(QtWidgets.QDialog, Ui_Dialog):
|
||||||
def __init__(self, title):
|
def __init__(self, title_id: list[int]):
|
||||||
super(NewEntry, self).__init__()
|
super(NewEntry, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.setWindowTitle("Neues Exemplar hinzufügen")
|
self.setWindowTitle("Neues Exemplar hinzufügen")
|
||||||
|
self.setWindowIcon(Icon("newentry").overwriteColor("#ffffff"))
|
||||||
self.tableWidget.horizontalHeader().setSectionResizeMode(
|
self.tableWidget.horizontalHeader().setSectionResizeMode(
|
||||||
QtWidgets.QHeaderView.ResizeMode.Stretch
|
QtWidgets.QHeaderView.ResizeMode.Stretch
|
||||||
)
|
)
|
||||||
self.db = Database()
|
self.db = Database()
|
||||||
self.titles = title
|
self.titles = title_id
|
||||||
|
self.newIds = []
|
||||||
self.populateTable()
|
self.populateTable()
|
||||||
self.btn_addNewBook.clicked.connect(self.addEntry)
|
self.btn_addNewBook.clicked.connect(self.addEntry)
|
||||||
self.buttonBox.accepted.connect(self.insertEntry)
|
self.buttonBox.accepted.connect(self.insertEntry)
|
||||||
@@ -26,16 +28,30 @@ class NewEntry(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
self.tableWidget.setItem(
|
self.tableWidget.setItem(
|
||||||
row, i, QtWidgets.QTableWidgetItem(self.tableWidget.item(row - 1, i))
|
row, i, QtWidgets.QTableWidgetItem(self.tableWidget.item(row - 1, i))
|
||||||
)
|
)
|
||||||
|
if i == 2 and "+" in self.tableWidget.item(row, i).text():
|
||||||
|
entry = self.tableWidget.item(row, i).text().split("+")[1]
|
||||||
|
entry = str(int(entry) + 1)
|
||||||
|
self.tableWidget.setItem(
|
||||||
|
row,
|
||||||
|
i,
|
||||||
|
QtWidgets.QTableWidgetItem(
|
||||||
|
self.tableWidget.item(row, i).text().split("+")[0] + "+" + entry
|
||||||
|
),
|
||||||
|
)
|
||||||
def populateTable(self):
|
def populateTable(self):
|
||||||
for title in self.titles:
|
for title in self.titles:
|
||||||
print(title)
|
print(title)
|
||||||
entry = self.db.getMedia(title)
|
entries = self.db.getMediaSimilarSignatureByID(title)
|
||||||
self.tableWidget.insertRow(0)
|
# sort by signature
|
||||||
self.tableWidget.setItem(0, 0, QtWidgets.QTableWidgetItem(entry.isbn))
|
entries.sort(key=lambda x: x.signature, reverse=True)
|
||||||
self.tableWidget.setItem(0, 1, QtWidgets.QTableWidgetItem(entry.title))
|
for entry in entries:
|
||||||
self.tableWidget.setItem(0, 2, QtWidgets.QTableWidgetItem(entry.signature))
|
self.tableWidget.insertRow(0)
|
||||||
self.tableWidget.setItem(0, 3, QtWidgets.QTableWidgetItem(entry.ppn))
|
self.tableWidget.setItem(0, 0, QtWidgets.QTableWidgetItem(entry.isbn))
|
||||||
|
self.tableWidget.setItem(0, 1, QtWidgets.QTableWidgetItem(entry.title))
|
||||||
|
self.tableWidget.setItem(
|
||||||
|
0, 2, QtWidgets.QTableWidgetItem(entry.signature)
|
||||||
|
)
|
||||||
|
self.tableWidget.setItem(0, 3, QtWidgets.QTableWidgetItem(entry.ppn))
|
||||||
|
|
||||||
def insertEntry(self):
|
def insertEntry(self):
|
||||||
# get all rows, convert them to Book and insert into database
|
# get all rows, convert them to Book and insert into database
|
||||||
@@ -52,7 +68,8 @@ class NewEntry(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
)
|
)
|
||||||
print(book)
|
print(book)
|
||||||
if not self.db.checkMediaExists(book):
|
if not self.db.checkMediaExists(book):
|
||||||
self.db.insertMedia(book)
|
newBookId = self.db.insertMedia(book)
|
||||||
|
self.newIds.append(newBookId)
|
||||||
|
|
||||||
|
|
||||||
def launch():
|
def launch():
|
||||||
|
|||||||
137
src/ui/settings.py
Normal file
137
src/ui/settings.py
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
from .sources.Ui_dialog_settings import Ui_Dialog
|
||||||
|
from PyQt6 import QtWidgets, QtCore
|
||||||
|
from src.utils import Icon
|
||||||
|
from src import config
|
||||||
|
from omegaconf import OmegaConf
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(QtWidgets.QDialog, Ui_Dialog):
|
||||||
|
def __init__(self):
|
||||||
|
super(Settings, self).__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.setWindowTitle("Einstellungen")
|
||||||
|
self.setWindowIcon(Icon("settings").icon)
|
||||||
|
self.originalSettings = config
|
||||||
|
|
||||||
|
# lineedits
|
||||||
|
self.institution_name.textChanged.connect(self.enableButtonBox)
|
||||||
|
self.default_loan_duration.textChanged.connect(self.enableButtonBox)
|
||||||
|
self.database_backupLocation.textChanged.connect(self.enableButtonBox)
|
||||||
|
self.database_path.textChanged.connect(self.enableButtonBox)
|
||||||
|
self.database_name.textChanged.connect(self.enableButtonBox)
|
||||||
|
self.database_name.textChanged.connect(self.enableButtonBox)
|
||||||
|
|
||||||
|
# buttonbox
|
||||||
|
self.buttonBox.accepted.connect(self.saveSettings)
|
||||||
|
self.buttonBox.rejected.connect(self.close)
|
||||||
|
self.loadSettings()
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).clicked.connect(self.DiscardSettings)
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).setEnabled(False)
|
||||||
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
False
|
||||||
|
)
|
||||||
|
|
||||||
|
# buttons
|
||||||
|
self.btn_select_database_backupLocation.clicked.connect(
|
||||||
|
self.selectBackupLocation
|
||||||
|
)
|
||||||
|
self.btn_select_database_path.clicked.connect(self.selectDatabasePath)
|
||||||
|
self.btn_select_database_name.clicked.connect(self.selectDatabaseName)
|
||||||
|
|
||||||
|
def enableButtonBox(self):
|
||||||
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).setEnabled(True)
|
||||||
|
|
||||||
|
def selectBackupLocation(self):
|
||||||
|
backupLocation = QtWidgets.QFileDialog.getExistingDirectory(
|
||||||
|
self,
|
||||||
|
"Select Backup Location",
|
||||||
|
self.originalSettings.database.backupLocation,
|
||||||
|
)
|
||||||
|
self.database_backupLocation.setText(backupLocation)
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).setEnabled(True)
|
||||||
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
|
def selectDatabasePath(self):
|
||||||
|
databasePath = QtWidgets.QFileDialog.getExistingDirectory(
|
||||||
|
self, "Select Database Path", self.originalSettings.database.path
|
||||||
|
)
|
||||||
|
self.database_path.setText(databasePath)
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).setEnabled(True)
|
||||||
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
|
def selectDatabaseName(self):
|
||||||
|
# filepicker with filter to select only .db files if a file is selected, set name to the lineedit and set database_path
|
||||||
|
databaseName = QtWidgets.QFileDialog.getOpenFileName(
|
||||||
|
self,
|
||||||
|
"Select Database",
|
||||||
|
self.originalSettings.database.path,
|
||||||
|
"Database Files (*.db)",
|
||||||
|
)
|
||||||
|
self.database_name.setText(databaseName[0])
|
||||||
|
self.database_path.setText(databaseName[0].rsplit("/", 1)[0])
|
||||||
|
self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Discard
|
||||||
|
).setEnabled(True)
|
||||||
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
|
def saveSettings(self):
|
||||||
|
# save settings to config file
|
||||||
|
institution_name = self.institution_name.text()
|
||||||
|
default_loan_duration = int(self.default_loan_duration.text())
|
||||||
|
database_backupLocation = self.database_backupLocation.text()
|
||||||
|
database_path = self.database_path.text()
|
||||||
|
database_name = self.database_name.text()
|
||||||
|
# overwrite the original settings
|
||||||
|
self.originalSettings.institution_name = institution_name
|
||||||
|
self.originalSettings.default_loan_duration = default_loan_duration
|
||||||
|
self.originalSettings.database.backupLocation = database_backupLocation
|
||||||
|
self.originalSettings.database.path = database_path
|
||||||
|
self.originalSettings.database.name = database_name
|
||||||
|
# save the new settings
|
||||||
|
OmegaConf.save(self.originalSettings, "config/settings.yaml")
|
||||||
|
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def DiscardSettings(self):
|
||||||
|
self.loadSettings()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def loadSettings(self):
|
||||||
|
self.institution_name.setText(self.originalSettings.institution_name)
|
||||||
|
self.default_loan_duration.setText(
|
||||||
|
str(self.originalSettings.default_loan_duration)
|
||||||
|
)
|
||||||
|
self.database_backupLocation.setText(
|
||||||
|
self.originalSettings.database.backupLocation
|
||||||
|
)
|
||||||
|
self.database_path.setText(self.originalSettings.database.path)
|
||||||
|
self.database_name.setText(self.originalSettings.database.name)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def launch():
|
||||||
|
import sys
|
||||||
|
|
||||||
|
app = QtWidgets.QApplication([])
|
||||||
|
settings = Settings()
|
||||||
|
settings.show()
|
||||||
|
sys.exit(app.exec())
|
||||||
92
src/ui/sources/Ui_dialog_settings.py
Normal file
92
src/ui/sources/Ui_dialog_settings.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
# Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\LibrarySystem\src\ui\sources\dialog_settings.ui'
|
||||||
|
#
|
||||||
|
# Created by: PyQt6 UI code generator 6.6.1
|
||||||
|
#
|
||||||
|
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||||
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
class Ui_Dialog(object):
|
||||||
|
def setupUi(self, Dialog):
|
||||||
|
Dialog.setObjectName("Dialog")
|
||||||
|
Dialog.resize(377, 206)
|
||||||
|
self.formLayout = QtWidgets.QFormLayout(Dialog)
|
||||||
|
self.formLayout.setObjectName("formLayout")
|
||||||
|
self.label = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label.setObjectName("label")
|
||||||
|
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label)
|
||||||
|
self.institution_name = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.institution_name.setObjectName("institution_name")
|
||||||
|
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.institution_name)
|
||||||
|
self.label_2 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_2.setObjectName("label_2")
|
||||||
|
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_2)
|
||||||
|
self.default_loan_duration = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.default_loan_duration.setObjectName("default_loan_duration")
|
||||||
|
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.default_loan_duration)
|
||||||
|
self.label_3 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_3.setObjectName("label_3")
|
||||||
|
self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_3)
|
||||||
|
self.gridLayout = QtWidgets.QGridLayout()
|
||||||
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
|
self.database_name = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.database_name.setObjectName("database_name")
|
||||||
|
self.gridLayout.addWidget(self.database_name, 1, 1, 1, 1)
|
||||||
|
self.label_4 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_4.setObjectName("label_4")
|
||||||
|
self.gridLayout.addWidget(self.label_4, 0, 0, 1, 1)
|
||||||
|
self.label_6 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_6.setObjectName("label_6")
|
||||||
|
self.gridLayout.addWidget(self.label_6, 2, 0, 1, 1)
|
||||||
|
self.database_path = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.database_path.setObjectName("database_path")
|
||||||
|
self.gridLayout.addWidget(self.database_path, 0, 1, 1, 1)
|
||||||
|
self.database_backupLocation = QtWidgets.QLineEdit(parent=Dialog)
|
||||||
|
self.database_backupLocation.setObjectName("database_backupLocation")
|
||||||
|
self.gridLayout.addWidget(self.database_backupLocation, 2, 1, 1, 1)
|
||||||
|
self.label_5 = QtWidgets.QLabel(parent=Dialog)
|
||||||
|
self.label_5.setObjectName("label_5")
|
||||||
|
self.gridLayout.addWidget(self.label_5, 1, 0, 1, 1)
|
||||||
|
self.btn_select_database_path = QtWidgets.QToolButton(parent=Dialog)
|
||||||
|
self.btn_select_database_path.setObjectName("btn_select_database_path")
|
||||||
|
self.gridLayout.addWidget(self.btn_select_database_path, 0, 2, 1, 1)
|
||||||
|
self.btn_select_database_name = QtWidgets.QToolButton(parent=Dialog)
|
||||||
|
self.btn_select_database_name.setObjectName("btn_select_database_name")
|
||||||
|
self.gridLayout.addWidget(self.btn_select_database_name, 1, 2, 1, 1)
|
||||||
|
self.btn_select_database_backupLocation = QtWidgets.QToolButton(parent=Dialog)
|
||||||
|
self.btn_select_database_backupLocation.setObjectName("btn_select_database_backupLocation")
|
||||||
|
self.gridLayout.addWidget(self.btn_select_database_backupLocation, 2, 2, 1, 1)
|
||||||
|
self.formLayout.setLayout(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.gridLayout)
|
||||||
|
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
|
||||||
|
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||||
|
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Discard|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||||
|
self.buttonBox.setObjectName("buttonBox")
|
||||||
|
self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.FieldRole, self.buttonBox)
|
||||||
|
|
||||||
|
self.retranslateUi(Dialog)
|
||||||
|
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
|
||||||
|
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
|
||||||
|
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||||
|
Dialog.setTabOrder(self.institution_name, self.default_loan_duration)
|
||||||
|
Dialog.setTabOrder(self.default_loan_duration, self.database_path)
|
||||||
|
Dialog.setTabOrder(self.database_path, self.database_name)
|
||||||
|
Dialog.setTabOrder(self.database_name, self.database_backupLocation)
|
||||||
|
Dialog.setTabOrder(self.database_backupLocation, self.btn_select_database_path)
|
||||||
|
Dialog.setTabOrder(self.btn_select_database_path, self.btn_select_database_name)
|
||||||
|
Dialog.setTabOrder(self.btn_select_database_name, self.btn_select_database_backupLocation)
|
||||||
|
|
||||||
|
def retranslateUi(self, Dialog):
|
||||||
|
_translate = QtCore.QCoreApplication.translate
|
||||||
|
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||||
|
self.label.setText(_translate("Dialog", "Name der Einrichtung"))
|
||||||
|
self.label_2.setText(_translate("Dialog", "Leihdauer in Tagen"))
|
||||||
|
self.label_3.setText(_translate("Dialog", "Datenbank"))
|
||||||
|
self.label_4.setText(_translate("Dialog", "Speicherort"))
|
||||||
|
self.label_6.setText(_translate("Dialog", "Sicherungspfad"))
|
||||||
|
self.label_5.setText(_translate("Dialog", "Datenbankname"))
|
||||||
|
self.btn_select_database_path.setText(_translate("Dialog", "..."))
|
||||||
|
self.btn_select_database_name.setText(_translate("Dialog", "..."))
|
||||||
|
self.btn_select_database_backupLocation.setText(_translate("Dialog", "..."))
|
||||||
156
src/ui/sources/dialog_settings.ui
Normal file
156
src/ui/sources/dialog_settings.ui
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>377</width>
|
||||||
|
<height>206</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name der Einrichtung</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="institution_name"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Leihdauer in Tagen</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="default_loan_duration"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Datenbank</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="database_name"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Speicherort</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
|
<property name="text">
|
||||||
|
<string>Sicherungspfad</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="database_path"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="database_backupLocation"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Datenbankname</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QToolButton" name="btn_select_database_path">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QToolButton" name="btn_select_database_name">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QToolButton" name="btn_select_database_backupLocation">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Discard|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>institution_name</tabstop>
|
||||||
|
<tabstop>default_loan_duration</tabstop>
|
||||||
|
<tabstop>database_path</tabstop>
|
||||||
|
<tabstop>database_name</tabstop>
|
||||||
|
<tabstop>database_backupLocation</tabstop>
|
||||||
|
<tabstop>btn_select_database_path</tabstop>
|
||||||
|
<tabstop>btn_select_database_name</tabstop>
|
||||||
|
<tabstop>btn_select_database_backupLocation</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
107
src/ui/user.py
107
src/ui/user.py
@@ -2,6 +2,8 @@ from .sources.Ui_main_userData import Ui_MainWindow
|
|||||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||||
from src.logic import Database
|
from src.logic import Database
|
||||||
from src.schemas import User
|
from src.schemas import User
|
||||||
|
from .extendLoan import ExtendLoan
|
||||||
|
from src.utils.stringtodate import stringToDate
|
||||||
class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||||
def __init__(self, u_name, u_no, u_mail):
|
def __init__(self, u_name, u_no, u_mail):
|
||||||
super(UserUI, self).__init__()
|
super(UserUI, self).__init__()
|
||||||
@@ -11,12 +13,27 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
self.userno = u_no
|
self.userno = u_no
|
||||||
self.usermail = u_mail
|
self.usermail = u_mail
|
||||||
self.setFields()
|
self.setFields()
|
||||||
|
self.userMedia = []
|
||||||
|
self.loadMedia()
|
||||||
# Buttons
|
# Buttons
|
||||||
self.btn_userChange_save.clicked.connect(self.saveChanges)
|
self.btn_userChange_save.clicked.connect(self.saveChanges)
|
||||||
self.btn_userchange_cancel.clicked.connect(self.discardChanges)
|
self.btn_userchange_cancel.clicked.connect(self.discardChanges)
|
||||||
|
self.btn_extendSelectedMedia.clicked.connect(self.extendLoan)
|
||||||
|
|
||||||
|
# radioButtons
|
||||||
|
self.radio_allLoanedMedia.clicked.connect(self.loadMedia)
|
||||||
|
self.radio_currentlyLoaned.clicked.connect(self.loadMedia)
|
||||||
|
self.radio_overdueLoans.clicked.connect(self.loadMedia)
|
||||||
|
|
||||||
# frames
|
# frames
|
||||||
self.frame.hide()
|
self.frame.hide()
|
||||||
|
|
||||||
|
# table
|
||||||
|
self.UserMediaTable.horizontalHeader().setSectionResizeMode(
|
||||||
|
QtWidgets.QHeaderView.ResizeMode.Stretch
|
||||||
|
)
|
||||||
|
# if one or more rows is selected, enable btn
|
||||||
|
self.UserMediaTable.itemSelectionChanged.connect(self.userTableAction)
|
||||||
# LineEdits
|
# LineEdits
|
||||||
# self.frame.hide()
|
# self.frame.hide()
|
||||||
|
|
||||||
@@ -26,6 +43,32 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
def extendLoan(self):
|
||||||
|
extend = ExtendLoan(self.username, self.userMedia)
|
||||||
|
extend.exec()
|
||||||
|
extendDate = extend.extendDate.toString()
|
||||||
|
# print columns of selected rows
|
||||||
|
for item in self.UserMediaTable.selectedItems():
|
||||||
|
if item.column() == 1:
|
||||||
|
signature = item.text()
|
||||||
|
print(signature)
|
||||||
|
self.db.extendLoanDuration(signature, extendDate)
|
||||||
|
self.userMedia = []
|
||||||
|
break
|
||||||
|
self.UserMediaTable.setRowCount(0)
|
||||||
|
self.loadMedia()
|
||||||
|
|
||||||
|
def userTableAction(self):
|
||||||
|
if self.UserMediaTable.selectedItems():
|
||||||
|
# if any selected item has a value in column 5, disable btn
|
||||||
|
for item in self.UserMediaTable.selectedItems():
|
||||||
|
if item.column() == 5 and item.text() != "":
|
||||||
|
self.btn_extendSelectedMedia.setEnabled(False)
|
||||||
|
return
|
||||||
|
self.btn_extendSelectedMedia.setEnabled(True)
|
||||||
|
else:
|
||||||
|
self.btn_extendSelectedMedia.setEnabled(False)
|
||||||
|
|
||||||
def showFrame(self):
|
def showFrame(self):
|
||||||
self.frame.show()
|
self.frame.show()
|
||||||
|
|
||||||
@@ -40,3 +83,67 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def discardChanges(self):
|
def discardChanges(self):
|
||||||
self.setFields()
|
self.setFields()
|
||||||
self.frame.hide()
|
self.frame.hide()
|
||||||
|
|
||||||
|
def loadMedia(self):
|
||||||
|
mode = (
|
||||||
|
"all"
|
||||||
|
if self.radio_allLoanedMedia.isChecked()
|
||||||
|
else "current"
|
||||||
|
if self.radio_currentlyLoaned.isChecked()
|
||||||
|
else "overdue"
|
||||||
|
)
|
||||||
|
print(mode)
|
||||||
|
if self.userMedia == []:
|
||||||
|
books = self.db.getAllMedia(self.userno)
|
||||||
|
for book in books:
|
||||||
|
self.userMedia.append(book)
|
||||||
|
print(self.userMedia)
|
||||||
|
self.UserMediaTable.setRowCount(0)
|
||||||
|
|
||||||
|
for book in self.userMedia:
|
||||||
|
# fromdate = stringToDate(book.loan_from)
|
||||||
|
todate = stringToDate(book.loan_to)
|
||||||
|
if mode == "current":
|
||||||
|
# book not returned
|
||||||
|
if book.returned == 0:
|
||||||
|
self.addBookToTable(book)
|
||||||
|
elif mode == "overdue":
|
||||||
|
# book not returned and todays date is greater than todate
|
||||||
|
if (
|
||||||
|
book.returned == 0
|
||||||
|
and QtCore.QDate.fromString(todate) > QtCore.QDate.currentDate()
|
||||||
|
):
|
||||||
|
self.addBookToTable(book)
|
||||||
|
else:
|
||||||
|
self.addBookToTable(book)
|
||||||
|
|
||||||
|
def addBookToTable(self, book):
|
||||||
|
self.UserMediaTable.insertRow(0)
|
||||||
|
# item0 = isbn
|
||||||
|
# item1 = signature
|
||||||
|
# item2 = title
|
||||||
|
# item3 = loan date
|
||||||
|
# item4 = return date
|
||||||
|
# item5 = returned_date
|
||||||
|
self.UserMediaTable.setItem(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
QtWidgets.QTableWidgetItem(book.isbn if book.isbn != "None" else ""),
|
||||||
|
)
|
||||||
|
self.UserMediaTable.setItem(0, 1, QtWidgets.QTableWidgetItem(book.signature))
|
||||||
|
self.UserMediaTable.setItem(0, 2, QtWidgets.QTableWidgetItem(book.title))
|
||||||
|
self.UserMediaTable.setItem(0, 3, QtWidgets.QTableWidgetItem(book.loan_from))
|
||||||
|
self.UserMediaTable.setItem(0, 4, QtWidgets.QTableWidgetItem(book.loan_to))
|
||||||
|
self.UserMediaTable.setItem(
|
||||||
|
0, 5, QtWidgets.QTableWidgetItem(book.returned_date)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def launch():
|
||||||
|
import sys
|
||||||
|
|
||||||
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|
||||||
|
window = UserUI("Test", "132", "sdf@f.de")
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec())
|
||||||
2
src/utils/__init__.py
Normal file
2
src/utils/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from .stringtodate import stringToDate
|
||||||
|
from .icon import Icon
|
||||||
Reference in New Issue
Block a user