user updates
This commit is contained in:
@@ -3,11 +3,20 @@ 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 .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):
|
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__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.setWindowTitle("Nutzerdaten")
|
||||||
|
self.setWindowIcon(Icon("user").icon)
|
||||||
self.db = Database()
|
self.db = Database()
|
||||||
self.username = u_name
|
self.username = u_name
|
||||||
self.userno = u_no
|
self.userno = u_no
|
||||||
@@ -35,6 +44,7 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
# if one or more rows is selected, enable btn
|
# if one or more rows is selected, enable btn
|
||||||
self.UserMediaTable.itemSelectionChanged.connect(self.userTableAction)
|
self.UserMediaTable.itemSelectionChanged.connect(self.userTableAction)
|
||||||
# LineEdits
|
# LineEdits
|
||||||
|
self.searchbox.textChanged.connect(self.limitResults)
|
||||||
# self.frame.hide()
|
# self.frame.hide()
|
||||||
|
|
||||||
self.name.textChanged.connect(self.showFrame)
|
self.name.textChanged.connect(self.showFrame)
|
||||||
@@ -46,17 +56,34 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
def extendLoan(self):
|
def extendLoan(self):
|
||||||
extend = ExtendLoan(self.username, self.userMedia)
|
extend = ExtendLoan(self.username, self.userMedia)
|
||||||
extend.exec()
|
extend.exec()
|
||||||
extendDate = extend.extendDate.toString()
|
if extend.result() == 1:
|
||||||
# print columns of selected rows
|
extendDate = extend.extendDate.toString()
|
||||||
for item in self.UserMediaTable.selectedItems():
|
# print columns of selected rows
|
||||||
if item.column() == 1:
|
for item in self.UserMediaTable.selectedItems():
|
||||||
signature = item.text()
|
if item.column() == 1:
|
||||||
print(signature)
|
signature = item.text()
|
||||||
self.db.extendLoanDuration(signature, extendDate)
|
print(signature)
|
||||||
self.userMedia = []
|
self.db.extendLoanDuration(signature, extendDate)
|
||||||
break
|
self.userMedia = []
|
||||||
|
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)
|
self.UserMediaTable.setRowCount(0)
|
||||||
self.loadMedia()
|
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):
|
def userTableAction(self):
|
||||||
if self.UserMediaTable.selectedItems():
|
if self.UserMediaTable.selectedItems():
|
||||||
@@ -105,17 +132,15 @@ class UserUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||||||
todate = stringToDate(book.loan_to)
|
todate = stringToDate(book.loan_to)
|
||||||
if mode == "current":
|
if mode == "current":
|
||||||
# book not returned
|
# book not returned
|
||||||
if book.returned == 0:
|
if book.returned == 1:
|
||||||
self.addBookToTable(book)
|
continue
|
||||||
elif mode == "overdue":
|
elif mode == "overdue":
|
||||||
# book not returned and todays date is greater than todate
|
# book not returned and todays date is greater than todate
|
||||||
if (
|
if book.returned_date != "":
|
||||||
book.returned == 0
|
continue
|
||||||
and QtCore.QDate.fromString(todate) > QtCore.QDate.currentDate()
|
if todate > QtCore.QDate.currentDate():
|
||||||
):
|
continue
|
||||||
self.addBookToTable(book)
|
self.addBookToTable(book)
|
||||||
else:
|
|
||||||
self.addBookToTable(book)
|
|
||||||
|
|
||||||
def addBookToTable(self, book):
|
def addBookToTable(self, book):
|
||||||
self.UserMediaTable.insertRow(0)
|
self.UserMediaTable.insertRow(0)
|
||||||
@@ -144,6 +169,6 @@ def launch():
|
|||||||
|
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|
||||||
window = UserUI("Test", "132", "sdf@f.de")
|
window = UserUI("Test", "3613899476", "sdf@f.de")
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
Reference in New Issue
Block a user