From 61b9f7001a7ad608e1abc362f60c334705705cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Mon, 24 Feb 2020 12:19:52 +0100 Subject: [PATCH] finished ##187 --- geruecht/controller/userController.py | 10 +++++++- geruecht/vorstand/routes.py | 36 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index cabf70b..0f7c293 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -17,12 +17,20 @@ class UserController(metaclass=Singleton): def __init__(self): pass + def setLockedDay(self, date, locked,hard=False): + return db.setLockedDay(date.date(), locked, hard) + def getLockedDay(self, date): now = datetime.now() daysInMonth = calendar.monthrange(date.year, date.month)[1] if date.year <= now.year and date.month <= now.month: for i in range(1, daysInMonth + 1): - db.setLockedDay(datetime(date.year, date.month, i).date(), True) + self.setLockedDay(datetime(date.year, date.month, i), True) + for i in range(1, 8): + nextMonth = datetime(date.year, date.month + 1, i) + if nextMonth.weekday() == 2: + break + self.setLockedDay(nextMonth, True) return db.getLockedDay(date.date()) def getWorker(self, date, username=None): diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 40c6234..8e6ff0d 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -70,4 +70,38 @@ def _deletUser(**kwargs): year = data['year'] date = datetime(year, month, day, 12) userController.deleteWorker(user['username'], date) - return jsonify({"ok": "ok"}) \ No newline at end of file + return jsonify({"ok": "ok"}) + +@vorstand.route("/sm/lockDay", methods=['POST']) +@login_required(groups=[MONEY, GASTRO]) +def _lockDay(**kwargs): + try: + data = request.get_json() + year = data['year'] + month = data['month'] + day = data['day'] + locked = data['locked'] + date = datetime(year, month, day, 12) + lockedDay = userController.setLockedDay(date, locked, True) + if not lockedDay: + retVal = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': False + } + else: + retVal = { + 'date': { + 'year': year, + 'month': month, + 'day': day + }, + 'locked': lockedDay['locked'] + } + print(retVal) + return jsonify(retVal) + except Exception as err: + return jsonify({'error': err}), 409 \ No newline at end of file