database reason rework, auto-report and auto user deletion after set time in settings
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import sys
|
||||
import atexit
|
||||
import datetime
|
||||
from src import config
|
||||
from src.logic import Database, Catalogue, Backup
|
||||
from src.utils import stringToDate, Icon, Log
|
||||
from src.utils import debugMessage as dbg
|
||||
from src.utils.createReport import generate_report
|
||||
from src.schemas import Book
|
||||
from .sources.Ui_main_UserInterface import Ui_MainWindow
|
||||
from .user import UserUI
|
||||
@@ -168,6 +170,8 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.input_username.setText(self.activeUser.username)
|
||||
self.input_userno.setText(str(self.activeUser.id))
|
||||
self.userdata.setText(self.activeUser.__repr__())
|
||||
today = QtCore.QDate.currentDate().toString("yyyy-MM-dd")
|
||||
self.db.setUserActiveDate(self.activeUser.id, today)
|
||||
# self.mode.setText("Ausleihe")
|
||||
|
||||
def createUser(self):
|
||||
@@ -391,6 +395,12 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def exit_handler():
|
||||
dbg("Exiting, creating backup")
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
print(backup.backup)
|
||||
# generate report if monday
|
||||
if datetime.datetime.now().weekday() == 0:
|
||||
generate_report()
|
||||
dbg("Generated Report")
|
||||
Database().renameInactiveUsers()
|
||||
if config.database.do_backup:
|
||||
state = backup.createBackup()
|
||||
# create dialog to show state
|
||||
@@ -408,13 +418,11 @@ def exit_handler():
|
||||
else:
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
# set icon
|
||||
reason = (
|
||||
"Backup deaktiviert"
|
||||
if config.database.do_backup is False
|
||||
else "Backuppfad nicht gefunden"
|
||||
if not backup.backup
|
||||
else "Unbekannter Fehler"
|
||||
)
|
||||
reason = "Unbekannter Grund"
|
||||
if config.database.do_backup is False:
|
||||
reason = "Backup deaktiviert"
|
||||
if backup.backup is False:
|
||||
reason = "Backuppfad nicht gefunden"
|
||||
dialog.setWindowIcon(Icon("backup").icon)
|
||||
dialog.setWindowTitle("Backup nicht möglich")
|
||||
dialog.setText("Backup konnte nicht erstellt werden\nGrund: {}".format(reason))
|
||||
|
||||
Reference in New Issue
Block a user