finished ##185
This commit is contained in:
parent
65d09225b1
commit
12ca655d02
|
@ -6,7 +6,7 @@ import calendar
|
|||
from geruecht.model.user import User
|
||||
from geruecht.exceptions import PermissionDenied
|
||||
from datetime import datetime, timedelta
|
||||
from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion
|
||||
from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExecption, LDAPExcetpion, DayLocked
|
||||
|
||||
db = dc.DatabaseController()
|
||||
ldap = lc.LDAPController(ldapConfig['dn'])
|
||||
|
@ -31,7 +31,12 @@ class UserController(metaclass=Singleton):
|
|||
return [db.getWorker(user, date)]
|
||||
return db.getWorkers(date)
|
||||
|
||||
def addWorker(self, username, date):
|
||||
def addWorker(self, username, date, userExc=False):
|
||||
if (userExc):
|
||||
lockedDay = self.getLockedDay(date)
|
||||
if lockedDay:
|
||||
if lockedDay['locked']:
|
||||
raise DayLocked("Day is locked. You can't get the Job")
|
||||
user = self.getUser(username)
|
||||
if (not db.getWorker(user, date)):
|
||||
db.setWorker(user, date)
|
||||
|
|
|
@ -8,3 +8,5 @@ class DatabaseExecption(Exception):
|
|||
pass
|
||||
class LDAPExcetpion(Exception):
|
||||
pass
|
||||
class DayLocked(Exception):
|
||||
pass
|
|
@ -3,8 +3,7 @@ from geruecht.decorator import login_required
|
|||
import geruecht.controller.userController as uc
|
||||
from geruecht.model import USER
|
||||
from datetime import datetime
|
||||
import time
|
||||
import traceback
|
||||
from geruecht.exceptions import DayLocked
|
||||
|
||||
user = Blueprint("user", __name__)
|
||||
|
||||
|
@ -59,9 +58,48 @@ def _getUser(**kwargs):
|
|||
month = data['month']
|
||||
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']
|
||||
}
|
||||
retVal = {
|
||||
'worker': userController.getWorker(date),
|
||||
'day': userController.getLockedDay(date)
|
||||
'day': lockedDay
|
||||
}
|
||||
print(retVal)
|
||||
return jsonify(retVal)
|
||||
|
||||
@user.route("/user/addJob", methods=['POST'])
|
||||
@login_required(groups=[USER])
|
||||
def _addUser(**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)
|
||||
retVal = userController.addWorker(user.uid, date, userExc=True)
|
||||
print(retVal)
|
||||
return jsonify(retVal)
|
||||
except DayLocked as err:
|
||||
return jsonify({'error': err}), 403
|
||||
except Exception as err:
|
||||
return jsonify({'error': err}), 409
|
|
@ -34,9 +34,28 @@ def _getUser(**kwargs):
|
|||
month = data['month']
|
||||
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']
|
||||
}
|
||||
retVal = {
|
||||
'worker': userController.getWorker(date),
|
||||
'day': userController.getLockedDay(date)
|
||||
'day': lockedDay
|
||||
}
|
||||
print(retVal)
|
||||
return jsonify(retVal)
|
||||
|
|
Loading…
Reference in New Issue