closes #3, fix bug with user creation
This commit is contained in:
@@ -106,14 +106,16 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
log.info("Showing Settings")
|
||||
settings = Settings()
|
||||
settings.exec()
|
||||
if settings.settingschanged:
|
||||
# reload settings
|
||||
print(config)
|
||||
#print(config)
|
||||
|
||||
def changeMode(self):
|
||||
log.info("Changing Mode")
|
||||
dbg(f"Current mode: {self.activeState}")
|
||||
self.input_username.clear()
|
||||
stayReturn = False
|
||||
if self.userdata.toPlainText() != "":
|
||||
stayReturn = True
|
||||
self.userdata.clear()
|
||||
self.input_userno.clear()
|
||||
self.btn_show_lentmedia.setText("")
|
||||
@@ -123,7 +125,10 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.mediaOverview.setRowCount(0)
|
||||
self.activeUser = None #! remove if last user should be kept
|
||||
if self.activeState == "Rückgabe":
|
||||
self.activateLoanMode()
|
||||
if stayReturn:
|
||||
self.activateReturnMode()
|
||||
else: self.activateLoanMode()
|
||||
|
||||
|
||||
else:
|
||||
self.activateReturnMode()
|
||||
@@ -190,9 +195,10 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
user = CreateUser(fieldname="id", data="")
|
||||
user.exec()
|
||||
userid = user.userid
|
||||
print(userid)
|
||||
if userid:
|
||||
log.info(f"User created {userid}")
|
||||
data = self.db.getUser(userid)
|
||||
data = self.db.getUserBy("user_id", userid)
|
||||
self.activeUser = data
|
||||
# set user to active user
|
||||
self.setUserData()
|
||||
@@ -204,7 +210,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
def checkUser(self, fieldname, data):
|
||||
log.info(f"Checking User {fieldname}, {data}")
|
||||
# print("Checking User", fieldname, data)
|
||||
#print("Checking User", fieldname, data)
|
||||
# set fieldname as key and data as variable
|
||||
user = self.db.checkUserExists(fieldname, data)
|
||||
if not user:
|
||||
@@ -224,16 +230,16 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
multi.exec()
|
||||
self.activeUser = multi.userdata
|
||||
else:
|
||||
# print("User found", user[0])
|
||||
#print("User found", user[0])
|
||||
self.activeUser = user[0]
|
||||
|
||||
if self.activeUser is not None:
|
||||
log.info(f"User found {self.activeUser}")
|
||||
# print("User found", self.activeUser)
|
||||
#print("User found", self.activeUser)
|
||||
self.setUserData()
|
||||
self.input_file_ident.setFocus()
|
||||
self.mode.setText("Ausleihe")
|
||||
print(self.activeUser.__dict__)
|
||||
#print(self.activeUser.__dict__)
|
||||
loans = self.db.getActiveLoans(self.activeUser.id)
|
||||
dbg(loans=loans)
|
||||
self.btn_show_lentmedia.setText(loans)
|
||||
@@ -298,7 +304,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
elif book_id:
|
||||
if isinstance(book_id, list) and len(book_id) > 1:
|
||||
print("Multiple Books found")
|
||||
#print("Multiple Books found")
|
||||
# TODO: implement book selection dialog
|
||||
return
|
||||
else:
|
||||
@@ -307,7 +313,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
# check if book is already loaned
|
||||
loaned = self.db.checkLoanState(book_id[0])
|
||||
if loaned:
|
||||
# print("Book already loaned")
|
||||
#print("Book already loaned")
|
||||
self.setStatusTipMessage("Buch bereits entliehen")
|
||||
# dialog with yes no to create new entry
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
@@ -329,7 +335,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
newentry = NewEntry([book_id[0]])
|
||||
newentry.exec()
|
||||
self.setStatusTipMessage("Neues Exemplar hinzugefügt")
|
||||
# print(created_ids)
|
||||
#print(created_ids)
|
||||
self.input_file_ident.setEnabled(True)
|
||||
newentries = newentry.newIds
|
||||
if newentries:
|
||||
@@ -339,7 +345,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
dbg("inserted duplicated book into database")
|
||||
return
|
||||
else:
|
||||
# print("Book not loaned, loaning now")
|
||||
#print("Book not loaned, loaning now")
|
||||
self.loanMedia(user_id, book_id)
|
||||
|
||||
def loanMedia(self, user_id, book_id):
|
||||
@@ -350,7 +356,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.duedate.date().toString("yyyy-MM-dd"),
|
||||
)
|
||||
media = self.db.getMedia(book_id[0])
|
||||
print(media)
|
||||
#print(media)
|
||||
self.mediaOverview.insertRow(0)
|
||||
self.mediaOverview.setItem(0, 0, QtWidgets.QTableWidgetItem(media.signature))
|
||||
self.mediaOverview.setItem(0, 1, QtWidgets.QTableWidgetItem(media.title))
|
||||
@@ -366,19 +372,19 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.input_file_ident.setEnabled(True)
|
||||
|
||||
def returnMedia(self, identifier):
|
||||
# print("Returning Media", identifier)
|
||||
#print("Returning Media", identifier)
|
||||
# get book id from database
|
||||
# self.
|
||||
identifier = Book(
|
||||
isbn=identifier, title=identifier, signature=identifier, ppn=identifier
|
||||
)
|
||||
book_id = self.db.checkMediaExists(identifier)
|
||||
# print(book_id)
|
||||
#print(book_id)
|
||||
if book_id:
|
||||
# check if book is already loaned
|
||||
loaned = self.db.checkLoanState(book_id[0])
|
||||
if loaned:
|
||||
# print("Book already loaned, returning now")
|
||||
#print("Book already loaned, returning now")
|
||||
user = self.db.getUserByLoan(book_id[0])
|
||||
# set userdata in lineedits
|
||||
self.activeUser = user
|
||||
@@ -397,11 +403,12 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.db.getActiveLoans(self.activeUser.id)
|
||||
)
|
||||
else:
|
||||
# print("Book not loaned")
|
||||
#print("Book not loaned")
|
||||
self.setStatusTipMessage("Buch nicht entliehen")
|
||||
self.input_file_ident.clear()
|
||||
else:
|
||||
print("Book not found")
|
||||
dbg("Book not found")
|
||||
#print("Book not found")
|
||||
#self.input_file_ident.setPlaceholderText(f"Buch {identifier} nicht gefunden")
|
||||
|
||||
def setStatusTipMessage(self, message):
|
||||
@@ -414,7 +421,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def exit_handler():
|
||||
dbg("Exiting, creating backup")
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
print(backup.backup)
|
||||
#print(backup.backup)
|
||||
# generate report if monday
|
||||
if datetime.datetime.now().weekday() == config.report.report_day:
|
||||
generate_report()
|
||||
@@ -446,8 +453,15 @@ def exit_handler():
|
||||
dialog.setWindowTitle("Backup nicht möglich")
|
||||
dialog.setText("Backup konnte nicht erstellt werden\nGrund: {}".format(reason))
|
||||
dialog.exec()
|
||||
def launch(options = None):
|
||||
app = QtWidgets.QApplication(sys.argv if options is None else [options])
|
||||
def launch(*argv):
|
||||
options = sys.argv
|
||||
if argv:
|
||||
options += [arg for arg in argv]
|
||||
options = [arg for arg in options if arg.startswith("--")]
|
||||
#print("Launching Main UI")
|
||||
#print(options)
|
||||
|
||||
app = QtWidgets.QApplication([])
|
||||
main_ui = MainUI()
|
||||
atexit.register(exit_handler)
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user