user updates
This commit is contained in:
@@ -3,11 +3,20 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
from src.logic import Database
|
||||
from src.schemas import User
|
||||
from .extendLoan import ExtendLoan
|
||||
from src.utils.stringtodate import stringToDate
|
||||
from src.utils import stringToDate, Icon
|
||||
|
||||
TABLETOFIELDTRANSLATE = {
|
||||
"Titel": "title",
|
||||
"Signatur": "signature",
|
||||
}
|
||||
|
||||
|
||||
class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, u_name, u_no, u_mail):
|
||||
super(UserUI, self).__init__()
|
||||
self.setupUi(self)
|
||||
self.setWindowTitle("Nutzerdaten")
|
||||
self.setWindowIcon(Icon("user").icon)
|
||||
self.db = Database()
|
||||
self.username = u_name
|
||||
self.userno = u_no
|
||||
@@ -35,6 +44,7 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
# if one or more rows is selected, enable btn
|
||||
self.UserMediaTable.itemSelectionChanged.connect(self.userTableAction)
|
||||
# LineEdits
|
||||
self.searchbox.textChanged.connect(self.limitResults)
|
||||
# self.frame.hide()
|
||||
|
||||
self.name.textChanged.connect(self.showFrame)
|
||||
@@ -46,6 +56,7 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def extendLoan(self):
|
||||
extend = ExtendLoan(self.username, self.userMedia)
|
||||
extend.exec()
|
||||
if extend.result() == 1:
|
||||
extendDate = extend.extendDate.toString()
|
||||
# print columns of selected rows
|
||||
for item in self.UserMediaTable.selectedItems():
|
||||
@@ -57,6 +68,22 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
break
|
||||
self.UserMediaTable.setRowCount(0)
|
||||
self.loadMedia()
|
||||
return
|
||||
|
||||
def limitResults(self):
|
||||
limiter = self.searchbox.text().lower()
|
||||
searchfield = self.searchfilter.currentText()
|
||||
searchfield = TABLETOFIELDTRANSLATE[searchfield]
|
||||
# dbg(limiter=limiter, search=searchfield)
|
||||
|
||||
self.UserMediaTable.setRowCount(0)
|
||||
for loan in self.userMedia:
|
||||
print("looping loans")
|
||||
fielddata = eval(f"loan.{searchfield}")
|
||||
if isinstance(fielddata, str):
|
||||
fielddata = fielddata.lower()
|
||||
if limiter in fielddata:
|
||||
self.addBookToTable(loan)
|
||||
|
||||
def userTableAction(self):
|
||||
if self.UserMediaTable.selectedItems():
|
||||
@@ -105,16 +132,14 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
todate = stringToDate(book.loan_to)
|
||||
if mode == "current":
|
||||
# book not returned
|
||||
if book.returned == 0:
|
||||
self.addBookToTable(book)
|
||||
if book.returned == 1:
|
||||
continue
|
||||
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:
|
||||
if book.returned_date != "":
|
||||
continue
|
||||
if todate > QtCore.QDate.currentDate():
|
||||
continue
|
||||
self.addBookToTable(book)
|
||||
|
||||
def addBookToTable(self, book):
|
||||
@@ -144,6 +169,6 @@ def launch():
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
|
||||
window = UserUI("Test", "132", "sdf@f.de")
|
||||
window = UserUI("Test", "3613899476", "sdf@f.de")
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
Reference in New Issue
Block a user