From cc692bb82c94fe42ba1c17ca323529077e699101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Wed, 11 Mar 2020 18:32:57 +0100 Subject: [PATCH 1/3] add route /sm/getUsers updatet usercontroller for getUsers updatet getLockedDay -> only the day what requestet will be locked (if nessecerie) --- geruecht/controller/userController.py | 161 +++++++++++++++++--------- geruecht/vorstand/routes.py | 63 +++++++--- 2 files changed, 149 insertions(+), 75 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index ead76db..1a07598 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -11,10 +11,12 @@ from geruecht.logger import getDebugLogger db = dc.DatabaseController() ldap = lc.LDAPController() -emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email']) +emailController = ec.EmailController( + mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email']) debug = getDebugLogger() + class UserController(metaclass=Singleton): def __init__(self): @@ -36,7 +38,8 @@ class UserController(metaclass=Singleton): def setStatus(self, name): debug.info("set status of user {{ {} }}".format(name)) retVal = db.setStatus(name) - debug.debug("settet status of user {{ {} }} is {{ {} }}".format(name, retVal)) + debug.debug( + "settet status of user {{ {} }} is {{ {} }}".format(name, retVal)) return retVal def deleteStatus(self, status): @@ -50,15 +53,19 @@ class UserController(metaclass=Singleton): return retVal def updateStatusOfUser(self, username, status): - debug.info("update status {{ {} }} of user {{ {} }}".format(status, username)) + debug.info("update status {{ {} }} of user {{ {} }}".format( + status, username)) retVal = db.updateStatusOfUser(username, status) - debug.debug("updatet status of user {{ {} }} is {{ {} }}".format(username, retVal)) + debug.debug( + "updatet status of user {{ {} }} is {{ {} }}".format(username, retVal)) return retVal def updateVotingOfUser(self, username, voting): - debug.info("update voting {{ {} }} of user {{ {} }}".format(voting, username)) + debug.info("update voting {{ {} }} of user {{ {} }}".format( + voting, username)) retVal = db.updateVotingOfUser(username, voting) - debug.debug("updatet voting of user {{ {} }} is {{ {} }}".format(username, retVal)) + debug.debug( + "updatet voting of user {{ {} }} is {{ {} }}".format(username, retVal)) return retVal def deleteDrinkType(self, type): @@ -106,49 +113,61 @@ class UserController(metaclass=Singleton): return list def setTransactJob(self, from_user, to_user, date): - debug.info("set transact job from {{ {} }} to {{ {} }} on {{ {} }}".format(from_user, to_user, date)) + debug.info("set transact job from {{ {} }} to {{ {} }} on {{ {} }}".format( + from_user, to_user, date)) jobtransact = db.setTransactJob(from_user, to_user, date.date()) debug.debug("transact job is {{ {} }}".format(jobtransact)) debug.info("send mail with transact job to user") - emailController.sendMail(jobtransact['to_user'], 'jobtransact', jobtransact) + emailController.sendMail( + jobtransact['to_user'], 'jobtransact', jobtransact) return jobtransact def getTransactJobFromUser(self, user, date): - debug.info("get transact job from user {{ {} }} on {{ {} }}".format(user, date)) + debug.info( + "get transact job from user {{ {} }} on {{ {} }}".format(user, date)) retVal = db.getTransactJobFromUser(user, date.date()) - debug.debug("transact job from user {{ {} }} is {{ {} }}".format(user, retVal)) + debug.debug( + "transact job from user {{ {} }} is {{ {} }}".format(user, retVal)) return retVal def getAllTransactJobFromUser(self, user, date): - debug.info("get all transact job from user {{ {} }} start on {{ {} }}".format(user, date)) + debug.info( + "get all transact job from user {{ {} }} start on {{ {} }}".format(user, date)) retVal = db.getAllTransactJobFromUser(user, date.date()) debug.debug("all transact job are {{ {} }}".format(retVal)) return retVal def getAllTransactJobToUser(self, user, date): - debug.info("get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date)) + debug.info( + "get all transact job from to_user {{ {} }} start on {{ {} }}".format(user, date)) retVal = db.getAllTransactJobToUser(user, date.date()) debug.debug("all transact job are {{ {} }}".format(retVal)) return retVal def getTransactJob(self, from_user, to_user, date): - debug.info("get transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(from_user, to_user, date)) + debug.info("get transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format( + from_user, to_user, date)) retVal = db.getTransactJob(from_user, to_user, date.date()) debug.debug("transact job is {{ {} }}".format(retVal)) return retVal def deleteTransactJob(self, from_user, to_user, date): - debug.info("delete transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format(from_user, to_user, date)) + debug.info("delete transact job from user {{ {} }} to user {{ {} }} on {{ {} }}".format( + from_user, to_user, date)) transactJob = self.getTransactJob(from_user, to_user, date) debug.debug("transact job is {{ {} }}".format(transactJob)) if transactJob['answerd']: - debug.warning("transactjob {{ {} }} can not delete because is answerd") - raise TansactJobIsAnswerdException("TransactJob is already answerd") + debug.warning( + "transactjob {{ {} }} can not delete because is answerd") + raise TansactJobIsAnswerdException( + "TransactJob is already answerd") db.deleteTransactJob(from_user, to_user, date.date()) def answerdTransactJob(self, from_user, to_user, date, answer): - debug.info("answer transact job from user {{ {} }} to user {{ {} }} on {{ {} }} with answer {{ {} }}".format(from_user, to_user, date, answer)) - transactJob = db.updateTransactJob(from_user, to_user, date.date(), answer) + debug.info("answer transact job from user {{ {} }} to user {{ {} }} on {{ {} }} with answer {{ {} }}".format( + from_user, to_user, date, answer)) + transactJob = db.updateTransactJob( + from_user, to_user, date.date(), answer) debug.debug("transactjob is {{ {} }}".format(transactJob)) if answer: debug.info("add worker on date {{ {} }}".format(date)) @@ -156,11 +175,26 @@ class UserController(metaclass=Singleton): return transactJob def setLockedDay(self, date, locked, hard=False): - debug.info("set day locked on {{ {} }} with state {{ {} }}".format(date, locked)) + debug.info( + "set day locked on {{ {} }} with state {{ {} }}".format(date, locked)) retVal = db.setLockedDay(date.date(), locked, hard) debug.debug("seted day locked is {{ {} }}".format(retVal)) return retVal + def getLockedDays(self, from_date, to_date): + debug.info("get locked days from {{ {} }} to {{ {} }}".format( + from_date.date(), to_date.date())) + oneDay = timedelta(1) + delta = to_date.date() - from_date.date() + retVal = [] + startdate = from_date - oneDay + for _ in range(delta.days + 1): + startdate += oneDay + lockday = self.getLockedDay(startdate) + retVal.append(lockday) + debug.debug("lock days are {{ {} }}".format(retVal)) + return retVal + def getLockedDay(self, date): debug.info("get locked day on {{ {} }}".format(date)) now = datetime.now() @@ -173,33 +207,34 @@ class UserController(metaclass=Singleton): oldMonth = True break debug.debug("oldMonth is {{ {} }}".format(oldMonth)) - lockedYear = date.year - lockedMonth = date.month if date.month < now.month else now.month - 1 if oldMonth else now.month - daysInMonth = calendar.monthrange(lockedYear, lockedMonth)[1] - startDay = 1 - debug.debug("calculate start day of month") + lockedYear = now.year + lockedMonth = now.month if now.month < now.month else now.month - \ + 1 if oldMonth else now.month + endDay = 1 + debug.debug("calculate end day of month") for i in range(1, 8): - if datetime(lockedYear, lockedMonth, i).weekday() == 2: - startDay = i + nextMonth = datetime(lockedYear, lockedMonth + 1, i) + if nextMonth.weekday() == 2: + endDay = i break - debug.debug("start day of month is {{ {} }}".format(startDay)) - debug.debug("check if date should be locked") - if lockedYear <= now.year and lockedMonth <= now.month: - for i in range(startDay, daysInMonth + 1): - debug.debug("lock day {{ {} }}".format(datetime(lockedYear, lockedMonth, i))) - self.setLockedDay(datetime(lockedYear, lockedMonth, i), True) - for i in range(1, 8): - nextMonth = datetime(lockedYear, lockedMonth + 1, i) - if nextMonth.weekday() == 2: - break - debug.debug("lock day {{ {} }}".format(datetime(lockedYear, lockedMonth, i))) - self.setLockedDay(nextMonth, True) + + monthLockedEndDate = datetime(lockedYear, lockedMonth + 1, endDay) + debug.debug("get lock day from database") retVal = db.getLockedDay(date.date()) + if not retVal: + debug.debug( + "lock day not exists, retVal is {{ {} }}".format(retVal)) + if date.date() <= monthLockedEndDate.date(): + debug.debug("lock day {{ {} }}".format(date.date())) + self.setLockedDay(date, True) + retVal = db.getLockedDay(date.date()) + else: + retVal = {"daydate": date.date(), "locked": False} debug.debug("locked day is {{ {} }}".format(retVal)) return retVal def getWorker(self, date, username=None): - debug.info("get worker on {{ {} }}".format(username, date)) + debug.info("get worker {{ {} }} on {{ {} }}".format(username, date)) if (username): user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) @@ -230,7 +265,8 @@ class UserController(metaclass=Singleton): return retVal def deleteWorker(self, username, date, userExc=False): - debug.info("delete worker {{ {} }} on date {{ {} }}".format(username, date)) + debug.info( + "delete worker {{ {} }} on date {{ {} }}".format(username, date)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if userExc: @@ -238,9 +274,11 @@ class UserController(metaclass=Singleton): lockedDay = self.getLockedDay(date) if lockedDay: if lockedDay['locked']: - debug.debug("day is locked, check if accepted transact job exists") + debug.debug( + "day is locked, check if accepted transact job exists") transactJobs = self.getTransactJobFromUser(user, date) - debug.debug("transact job is {{ {} }}".format(transactJobs)) + debug.debug( + "transact job is {{ {} }}".format(transactJobs)) found = False for job in transactJobs: if job['accepted'] and job['answerd']: @@ -249,11 +287,13 @@ class UserController(metaclass=Singleton): break if not found: debug.debug("no accepted transact job found") - raise DayLocked("Day is locked. You can't delete the Job") + raise DayLocked( + "Day is locked. You can't delete the Job") db.deleteWorker(user, date) def lockUser(self, username, locked): - debug.info("lock user {{ {} }} for credit with status {{ {} }}".format(username, locked)) + debug.info("lock user {{ {} }} for credit with status {{ {} }}".format( + username, locked)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) user.updateData({'locked': locked}) @@ -263,7 +303,8 @@ class UserController(metaclass=Singleton): return retVal def updateConfig(self, username, data): - debug.info("update config of user {{ {} }} with config {{ {} }}".format(username, data)) + debug.info( + "update config of user {{ {} }} with config {{ {} }}".format(username, data)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) user.updateData(data) @@ -290,26 +331,30 @@ class UserController(metaclass=Singleton): credit = user.getGeruecht(year=datetime.now().year).getSchulden() limit = -1*user.limit if credit <= limit: - debug.debug("credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit)) + debug.debug( + "credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit)) debug.debug("lock user") user.updateData({'locked': True}) debug.debug("send mail to user") emailController.sendMail(user) else: - debug.debug("cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit)) + debug.debug( + "cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit)) debug.debug("unlock user") user.updateData({'locked': False}) db.updateUser(user) def addAmount(self, username, amount, year, month, finanzer=False): - debug.info("add amount {{ {} }} to user {{ {} }} no month {{ {} }}, year {{ {} }}".format(amount, username, month, year)) + debug.info("add amount {{ {} }} to user {{ {} }} no month {{ {} }}, year {{ {} }}".format( + amount, username, month, year)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if user.uid == 'extern': debug.debug("user is extern user, so exit add amount") return if not user.locked or finanzer: - debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format(user.locked, finanzer)) + debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format( + user.locked, finanzer)) user.addAmount(amount, year=year, month=month) creditLists = user.updateGeruecht() debug.debug("creditList is {{ {} }}".format(creditLists)) @@ -323,7 +368,8 @@ class UserController(metaclass=Singleton): return retVal def addCredit(self, username, credit, year, month): - debug.info("add credit {{ {} }} to user {{ {} }} on month {{ {} }}, year {{ {} }}".format(credit, username, month, year)) + debug.info("add credit {{ {} }} to user {{ {} }} on month {{ {} }}, year {{ {} }}".format( + credit, username, month, year)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if user.uid == 'extern': @@ -362,18 +408,19 @@ class UserController(metaclass=Singleton): date = datetime.now() zero = date.replace(hour=0, minute=0, second=0, microsecond=0) end = zero + timedelta(hours=12) - startdatetime = date.replace(hour=12, minute=0, second=0, microsecond=0) + startdatetime = date.replace( + hour=12, minute=0, second=0, microsecond=0) if date > zero and end > date: - startdatetime = startdatetime - timedelta(days=1) + startdatetime = startdatetime - timedelta(days=1) enddatetime = startdatetime + timedelta(days=1) - debug.debug("startdatetime is {{ {} }} and enddatetime is {{ {} }}".format(startdatetime, end)) + debug.debug("startdatetime is {{ {} }} and enddatetime is {{ {} }}".format( + startdatetime, end)) result = False if date >= startdatetime and date < enddatetime: result = db.getWorker(user, startdatetime) debug.debug("worker is {{ {} }}".format(result)) return True if result else False - def getUser(self, username): debug.info("get user {{ {} }}".format(username)) user = db.getUser(username) @@ -428,7 +475,8 @@ class UserController(metaclass=Singleton): return retVal def modifyUser(self, user, ldap_conn, attributes): - debug.info("modify user {{ {} }} with attributes {{ {} }} with ldap_conn {{ {} }}".format(user, attributes, ldap_conn)) + debug.info("modify user {{ {} }} with attributes {{ {} }} with ldap_conn {{ {} }}".format( + user, attributes, ldap_conn)) try: if 'username' in attributes: debug.debug("change username, so change first in database") @@ -443,7 +491,8 @@ class UserController(metaclass=Singleton): debug.debug("user is {{ {} }}".format(retVal)) return retVal except UsernameExistLDAP as err: - debug.debug("username exists on ldap, rechange username on database", exc_info=True) + debug.debug( + "username exists on ldap, rechange username on database", exc_info=True) db.changeUsername(user, user.uid) raise Exception(err) except LDAPExcetpion as err: diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index d470483..14035f3 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, jsonify -from datetime import datetime +from datetime import datetime, time import geruecht.controller.userController as uc import geruecht.controller.ldapController as lc from geruecht.decorator import login_required @@ -111,6 +111,41 @@ def _addUser(**kwargs): return jsonify({"error": str(err)}), 500 +@vorstand.route("/sm/getUsers", methods=['POST']) +@login_required(groups=[MONEY, GASTRO, VORSTAND]) +def _getUsers(**kwrags): + debug.info("/sm/getUsers") + try: + data = request.get_json() + from_date = data['from_date'] + to_date = data['to_date'] + from_date = datetime( + from_date['year'], from_date['month'], from_date['day']) + to_date = datetime(to_date['year'], to_date['month'], to_date['day']) + lockedDays = userController.getLockedDays(from_date, to_date) + retVal = [] + for lockedDay in lockedDays: + day = datetime.combine(lockedDay['daydate'], time(12)) + retDay = { + "worker": userController.getWorker(day), + "day": { + "date": { + "year": day.year, + "month": day.month, + "day": day.day + }, + "locked": lockedDay['locked'] + } + } + retVal.append(retDay) + + debug.debug("return {{ {} }}".format(retVal)) + return jsonify(retVal) + except Exception as err: + debug.debug("exception", exc_info=True) + return jsonify({"error": str(err)}), 500 + + @vorstand.route("/sm/getUser", methods=['POST']) @login_required(groups=[MONEY, GASTRO, VORSTAND]) def _getUser(**kwargs): @@ -122,24 +157,14 @@ def _getUser(**kwargs): year = data['year'] date = datetime(year, month, day, 12) lockedDay = userController.getLockedDay(date) - if not lockedDay: - lockedDay = { - 'date': { - 'year': year, - 'month': month, - 'day': day - }, - 'locked': False - } - else: - lockedDay = { - 'date': { - 'year': year, - 'month': month, - 'day': day - }, - 'locked': lockedDay['locked'] - } + lockedDay = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': lockedDay['locked'] + } retVal = { 'worker': userController.getWorker(date), 'day': lockedDay From b4d648530e5bfb889d5332528b80af207ac535a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 12 Mar 2020 10:16:50 +0100 Subject: [PATCH 2/3] fixed ##225 and ##226 --- geruecht/controller/userController.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 1a07598..63ce79b 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -212,13 +212,16 @@ class UserController(metaclass=Singleton): 1 if oldMonth else now.month endDay = 1 debug.debug("calculate end day of month") + lockedYear = lockedYear if lockedMonth != 12 else (lockedYear + 1) + lockedMonth = (lockedMonth + 1) if lockedMonth != 12 else 1 for i in range(1, 8): - nextMonth = datetime(lockedYear, lockedMonth + 1, i) + nextMonth = datetime(lockedYear, lockedMonth, i) if nextMonth.weekday() == 2: endDay = i break - monthLockedEndDate = datetime(lockedYear, lockedMonth + 1, endDay) + monthLockedEndDate = datetime( + lockedYear, lockedMonth, endDay) - timedelta(1) debug.debug("get lock day from database") retVal = db.getLockedDay(date.date()) if not retVal: From 2f756983c27a69779d01d2ec7b3107088764c0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 13 Mar 2020 19:06:24 +0200 Subject: [PATCH 3/3] add route for user for ##222 --- geruecht/user/routes.py | 104 ++++++++++++++++++++++++++++++++-------- 1 file changed, 84 insertions(+), 20 deletions(-) diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py index 357e784..79631f3 100644 --- a/geruecht/user/routes.py +++ b/geruecht/user/routes.py @@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify from geruecht.decorator import login_required import geruecht.controller.userController as uc from geruecht.model import USER -from datetime import datetime +from datetime import datetime, time from geruecht.exceptions import DayLocked from geruecht.logger import getDebugLogger, getCreditLogger, getJobsLogger @@ -14,6 +14,7 @@ debug = getDebugLogger() creditL = getCreditLogger() jobL = getJobsLogger() + @user.route("/user/main") @login_required(groups=[USER]) def _main(**kwargs): @@ -23,13 +24,15 @@ def _main(**kwargs): accToken = kwargs['accToken'] accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() - retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + retVal['creditList'] = {credit.year: credit.toJSON() + for credit in accToken.user.geruechte} debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception: debug.debug("exception", exc_info=True) return jsonify("error", "something went wrong"), 500 + @user.route("/user/addAmount", methods=['POST']) @login_required(groups=[USER]) def _addAmount(**kwargs): @@ -40,17 +43,21 @@ def _addAmount(**kwargs): data = request.get_json() amount = int(data['amount']) date = datetime.now() - userController.addAmount(accToken.user.uid, amount, year=date.year, month=date.month) + userController.addAmount( + accToken.user.uid, amount, year=date.year, month=date.month) accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() - retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + retVal['creditList'] = {credit.year: credit.toJSON() + for credit in accToken.user.geruechte} debug.debug("return {{ {} }}".format(retVal)) - creditL.info("{} {} {} fügt sich selbst {} € Schulden hinzu".format(date, accToken.user.firstname, accToken.user.lastname, amount/100)) + creditL.info("{} {} {} fügt sich selbst {} € Schulden hinzu".format( + date, accToken.user.firstname, accToken.user.lastname, amount/100)) return jsonify(retVal) except Exception: debug.debug("exception", exc_info=True) return jsonify({"error": "something went wrong"}), 500 + @user.route("/user/saveConfig", methods=['POST']) @login_required(groups=[USER]) def _saveConfig(**kwargs): @@ -59,15 +66,53 @@ def _saveConfig(**kwargs): if 'accToken' in kwargs: accToken = kwargs['accToken'] data = request.get_json() - accToken.user = userController.modifyUser(accToken.user, accToken.ldap_conn, data) + accToken.user = userController.modifyUser( + accToken.user, accToken.ldap_conn, data) retVal = accToken.user.toJSON() - retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + retVal['creditList'] = {credit.year: credit.toJSON() + for credit in accToken.user.geruechte} debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + +@user.route("/user/jobs", methods=['POST']) +@login_required(groups=[USER]) +def _getUsers(**kwrags): + debug.info("/user/jobs") + try: + data = request.get_json() + from_date = data['from_date'] + to_date = data['to_date'] + from_date = datetime( + from_date['year'], from_date['month'], from_date['day']) + to_date = datetime(to_date['year'], to_date['month'], to_date['day']) + lockedDays = userController.getLockedDays(from_date, to_date) + retVal = [] + for lockedDay in lockedDays: + day = datetime.combine(lockedDay['daydate'], time(12)) + retDay = { + "worker": userController.getWorker(day), + "day": { + "date": { + "year": day.year, + "month": day.month, + "day": day.day + }, + "locked": lockedDay['locked'] + } + } + retVal.append(retDay) + + debug.debug("return {{ {} }}".format(retVal)) + return jsonify(retVal) + except Exception as err: + debug.debug("exception", exc_info=True) + return jsonify({"error": str(err)}), 500 + + @user.route("/user/job", methods=['POST']) @login_required(groups=[USER]) def _getUser(**kwargs): @@ -107,6 +152,7 @@ def _getUser(**kwargs): debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 500 + @user.route("/user/addJob", methods=['POST']) @login_required(groups=[USER]) def _addUser(**kwargs): @@ -119,10 +165,11 @@ def _addUser(**kwargs): day = data['day'] month = data['month'] year = data['year'] - date = datetime(year,month,day,12) + date = datetime(year, month, day, 12) retVal = userController.addWorker(user.uid, date, userExc=True) debug.debug("return {{ {} }}".format(retVal)) - jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format(user.firstname, user.lastname, date.date())) + jobL.info("Mitglied {} {} schreib sich am {} zum Dienst ein.".format( + user.firstname, user.lastname, date.date())) return jsonify(retVal) except DayLocked as err: debug.debug("exception", exc_info=True) @@ -131,6 +178,7 @@ def _addUser(**kwargs): debug.debug("exception", exc_info=True) return jsonify({'error': str(err)}), 409 + @user.route("/user/deleteJob", methods=['POST']) @login_required(groups=[USER]) def _deletJob(**kwargs): @@ -143,10 +191,11 @@ def _deletJob(**kwargs): day = data['day'] month = data['month'] year = data['year'] - date = datetime(year,month,day,12) + date = datetime(year, month, day, 12) userController.deleteWorker(user.uid, date, True) debug.debug("return ok") - jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format(user.firstname, user.lastname, date.date())) + jobL.info("Mitglied {} {} entfernt sich am {} aus dem Dienst".format( + user.firstname, user.lastname, date.date())) return jsonify({"ok": "ok"}) except DayLocked as err: debug.debug("exception", exc_info=True) @@ -155,6 +204,7 @@ def _deletJob(**kwargs): debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/transactJob", methods=['POST']) @login_required(groups=[USER]) def _transactJob(**kwargs): @@ -177,12 +227,14 @@ def _transactJob(**kwargs): retVal['to_user'] = retVal['to_user'].toJSON() retVal['date'] = {'year': year, 'month': month, 'day': day} debug.debug("return {{ {} }}".format(retVal)) - jobL.info("Mitglied {} {} sendet Dienstanfrage an Mitglied {} {} am {}".format(from_userl.firstname, from_userl.lastname, to_userl.firstname, to_userl.lastname, date.date())) + jobL.info("Mitglied {} {} sendet Dienstanfrage an Mitglied {} {} am {}".format( + from_userl.firstname, from_userl.lastname, to_userl.firstname, to_userl.lastname, date.date())) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/answerTransactJob", methods=['POST']) @login_required(groups=[USER]) def _answer(**kwargs): @@ -199,19 +251,22 @@ def _answer(**kwargs): username = data['username'] date = datetime(year, month, day, 12) from_user = userController.getUser(username) - retVal = userController.answerdTransactJob(from_user, user, date, answer) + retVal = userController.answerdTransactJob( + from_user, user, date, answer) from_userl = retVal['from_user'] to_userl = retVal['to_user'] retVal['from_user'] = retVal['from_user'].toJSON() retVal['to_user'] = retVal['to_user'].toJSON() retVal['date'] = {'year': year, 'month': month, 'day': day} debug.debug("return {{ {} }}".format(retVal)) - jobL.info("Mitglied {} {} beantwortet Dienstanfrage von {} {} am {} mit {}".format(to_userl.firstname, to_userl.lastname, from_userl.firstname, from_userl.lastname, date.date(), 'JA' if answer else 'NEIN')) + jobL.info("Mitglied {} {} beantwortet Dienstanfrage von {} {} am {} mit {}".format(to_userl.firstname, + to_userl.lastname, from_userl.firstname, from_userl.lastname, date.date(), 'JA' if answer else 'NEIN')) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/jobRequests", methods=['POST']) @login_required(groups=[USER]) def _requests(**kwargs): @@ -230,13 +285,15 @@ def _requests(**kwargs): data['from_user'] = data['from_user'].toJSON() data['to_user'] = data['to_user'].toJSON() data_date = data['date'] - data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} + data['date'] = {'year': data_date.year, + 'month': data_date.month, 'day': data_date.day} debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/getTransactJobs", methods=['POST']) @login_required(groups=[USER]) def _getTransactJobs(**kwargs): @@ -255,13 +312,15 @@ def _getTransactJobs(**kwargs): data['from_user'] = data['from_user'].toJSON() data['to_user'] = data['to_user'].toJSON() data_date = data['date'] - data['date'] = {'year': data_date.year, 'month': data_date.month, 'day': data_date.day} + data['date'] = {'year': data_date.year, + 'month': data_date.month, 'day': data_date.day} debug.debug("return {{ {} }}".format(retVal)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/deleteTransactJob", methods=['POST']) @login_required(groups=[USER]) def _deleteTransactJob(**kwargs): @@ -279,12 +338,14 @@ def _deleteTransactJob(**kwargs): to_user = userController.getUser(username) userController.deleteTransactJob(from_user, to_user, date) debug.debug("return ok") - jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format(from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date())) + jobL.info("Mitglied {} {} entfernt Dienstanfrage an {} {} am {}".format( + from_user.firstname, from_user.lastname, to_user.firstname, to_user.lastname, date.date())) return jsonify({"ok": "ok"}) except Exception as err: debug.debug("exception", exc_info=True) return jsonify({"error": str(err)}), 409 + @user.route("/user/storno", methods=['POST']) @login_required(groups=[USER]) def _storno(**kwargs): @@ -306,12 +367,15 @@ def _storno(**kwargs): amount = int(data['amount']) date = datetime.now() - userController.addCredit(user.uid, amount, year=date.year, month=date.month) + userController.addCredit( + user.uid, amount, year=date.year, month=date.month) accToken.user = userController.getUser(accToken.user.uid) retVal = accToken.user.toJSON() - retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + retVal['creditList'] = {credit.year: credit.toJSON() + for credit in accToken.user.geruechte} debug.debug("return {{ {} }}".format(retVal)) - creditL.info("{} {} {} storniert {} €".format(date, user.firstname, user.lastname, amount/100)) + creditL.info("{} {} {} storniert {} €".format( + date, user.firstname, user.lastname, amount/100)) return jsonify(retVal) except Exception as err: debug.debug("exception", exc_info=True)