from datetime import time, datetime import geruecht.controller.databaseController as dc from geruecht.exceptions import DayLocked from geruecht.logger import getDebugLogger db = dc.DatabaseController() debug = getDebugLogger() class Base: def getWorker(self, date, username=None): debug.info("get worker {{ {} }} on {{ {} }}".format(username, date)) if (username): user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) retVal = [db.getWorker(user, date)] debug.debug("worker is {{ {} }}".format(retVal)) return retVal retVal = db.getWorkers(date) debug.debug("workers are {{ {} }}".format(retVal)) return retVal def addWorker(self, username, date, job_kind=None, userExc=False): debug.info("add job user {{ {} }} on {{ {} }} with job_kind {{ {} }}".format(username, date, job_kind)) if (userExc): debug.debug("this is a user execution, check if day is locked") lockedDay = self.getLockedDay(date) if lockedDay: if lockedDay['locked']: debug.debug("day is lockey. user cant get job") raise DayLocked("Day is locked. You can't get the Job") user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) debug.debug("check if user has job on date") if (not db.getWorker(user, date)): debug.debug("set job to user") db.setWorker(user, date, job_kind=job_kind) retVal = self.getWorker(date, username=username) debug.debug("worker on date is {{ {} }}".format(retVal)) return retVal def deleteWorker(self, username, date, userExc=False): debug.info( "delete worker {{ {} }} on date {{ {} }}".format(username, date)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if userExc: debug.debug("is user execution, check if day locked") lockedDay = self.getLockedDay(date) if lockedDay: if lockedDay['locked']: raise DayLocked( "Day is locked. You can't delete the Job") db.deleteWorker(user, date)