From f1b957c6ea8fefa16eef45349b3cf587a5638875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 7 Jun 2020 23:28:27 +0200 Subject: [PATCH] =?UTF-8?q?last=5Fseen=20hinzugef=C3=BCgt.=20dieser=20wert?= =?UTF-8?q?=20sagt=20an,=20wann=20das=20letzte=20mal=20vom=20bardienst=20e?= =?UTF-8?q?twas=20hinzugef=C3=BCgt=20wird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geruecht/baruser/routes.py | 3 +++ .../databaseController/dbUserController.py | 15 ++++++++++++++- .../mainController/mainCreditListController.py | 2 ++ geruecht/model/user.py | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index 2fc7b59..d078bc6 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -50,6 +50,7 @@ def _bar(**kwargs): "type": type, "limit": user.limit } + dic[user.uid]['last_seen'] = {"year": user.last_seen.year, "month": user.last_seen.month, "day": user.last_seen.day, "hour": user.last_seen.hour, "minute": user.last_seen.minute, "second": user.last_seen.second} if user.last_seen else None debug.debug("return {{ {} }}".format(dic)) return jsonify(dic) except Exception as err: @@ -89,6 +90,7 @@ def _baradd(**kwargs): dic = user.toJSON() dic['amount'] = all dic['type'] = type + dic['last_seen'] = {"year": user.last_seen.year, "month": user.last_seen.month, "day": user.last_seen.day, "hour": user.last_seen.hour, "minute": user.last_seen.minute, "second": user.last_seen.second} if user.last_seen else None debug.debug("return {{ {} }}".format(dic)) creditL.info("{} Baruser {} {} fügt {} {} {} € Schulden hinzu.".format( date, kwargs['accToken'].user.firstname, kwargs['accToken'].user.lastname, user.firstname, user.lastname, amountl/100)) @@ -178,6 +180,7 @@ def _getUser(**kwargs): retVal = user.toJSON() retVal['amount'] = amount retVal['type'] = type + debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: diff --git a/geruecht/controller/databaseController/dbUserController.py b/geruecht/controller/databaseController/dbUserController.py index e88940a..bc00b16 100644 --- a/geruecht/controller/databaseController/dbUserController.py +++ b/geruecht/controller/databaseController/dbUserController.py @@ -92,7 +92,6 @@ class Base: def updateUser(self, user): try: cursor = self.db.connection.cursor() - print('uid: {}; group: {}'.format(user.uid, user.group)) groups = self._convertGroupToString(user.group) sql = "update user set dn='{}', firstname='{}', lastname='{}', gruppe='{}', lockLimit={}, locked={}, autoLock={}, mail='{}' where uid='{}'".format( user.dn, user.firstname, user.lastname, groups, user.limit, user.locked, user.autoLock, user.mail, user.uid) @@ -104,6 +103,20 @@ class Base: self.db.connection.rollback() raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) + def updateLastSeen(self, user, time): + try: + cursor = self.db.connection.cursor() + sql = "update user set last_seen='{}' where uid='{}'".format( + time, user.uid) + print(sql) + cursor.execute(sql) + self.db.connection.commit() + + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Datatabase: {}".format(err)) + def changeUsername(self, user, newUsername): try: cursor= self.db.connection.cursor() diff --git a/geruecht/controller/mainController/mainCreditListController.py b/geruecht/controller/mainController/mainCreditListController.py index f6e24c2..844206b 100644 --- a/geruecht/controller/mainController/mainCreditListController.py +++ b/geruecht/controller/mainController/mainCreditListController.py @@ -41,6 +41,8 @@ class Base: debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format( user.locked, finanzer)) user.addAmount(amount, year=year, month=month) + user.last_seen = datetime.now() + db.updateLastSeen(user, user.last_seen) creditLists = user.updateGeruecht() debug.debug("creditList is {{ {} }}".format(creditLists)) for creditList in creditLists: diff --git a/geruecht/model/user.py b/geruecht/model/user.py index 1af0ffe..543859c 100644 --- a/geruecht/model/user.py +++ b/geruecht/model/user.py @@ -28,6 +28,9 @@ class User(): self.firstname = data['firstname'] self.lastname = data['lastname'] self.group = data['gruppe'] + self.last_seen = None + if 'last_seen' in data: + self.last_seen = data['last_seen'] if 'statusgroup' in data: self.statusgroup = data['statusgroup'] else: