finished ##193
route for user to delete job, but only if day not locked fixed a bug, that the month start on the first wednesday in month and ended in first tuesday in nextmonth
This commit is contained in:
parent
61b9f7001a
commit
4e91587731
|
@ -23,8 +23,13 @@ class UserController(metaclass=Singleton):
|
|||
def getLockedDay(self, date):
|
||||
now = datetime.now()
|
||||
daysInMonth = calendar.monthrange(date.year, date.month)[1]
|
||||
startMonth = 1
|
||||
for i in range(1, 8):
|
||||
if datetime(date.year, date.month, i).weekday() == 2:
|
||||
startMonth = i
|
||||
break
|
||||
if date.year <= now.year and date.month <= now.month:
|
||||
for i in range(1, daysInMonth + 1):
|
||||
for i in range(startMonth, daysInMonth + 1):
|
||||
self.setLockedDay(datetime(date.year, date.month, i), True)
|
||||
for i in range(1, 8):
|
||||
nextMonth = datetime(date.year, date.month + 1, i)
|
||||
|
@ -50,7 +55,12 @@ class UserController(metaclass=Singleton):
|
|||
db.setWorker(user, date)
|
||||
return self.getWorker(date, username=username)
|
||||
|
||||
def deleteWorker(self, username, date):
|
||||
def deleteWorker(self, username, date, userExc=False):
|
||||
if userExc:
|
||||
lockedDay = self.getLockedDay(date)
|
||||
if lockedDay:
|
||||
if lockedDay['locked']:
|
||||
raise DayLocked("Day is locked. You can't delete the Job")
|
||||
user = self.getUser(username)
|
||||
db.deleteWorker(user, date)
|
||||
|
||||
|
|
|
@ -103,3 +103,22 @@ def _addUser(**kwargs):
|
|||
return jsonify({'error': err}), 403
|
||||
except Exception as err:
|
||||
return jsonify({'error': err}), 409
|
||||
|
||||
@user.route("/user/deleteJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _deletJob(**kwargs):
|
||||
try:
|
||||
if 'accToken' in kwargs:
|
||||
accToken = kwargs['accToken']
|
||||
user = accToken.user
|
||||
data = request.get_json()
|
||||
day = data['day']
|
||||
month = data['month']
|
||||
year = data['year']
|
||||
date = datetime(year,month,day,12)
|
||||
userController.deleteWorker(user.uid, date, True)
|
||||
return jsonify({"ok": "ok"})
|
||||
except DayLocked as err:
|
||||
return jsonify({"error": err}), 403
|
||||
except Exception as err:
|
||||
return jsonify({"error": err}), 409
|
Loading…
Reference in New Issue