from datetime import date, timedelta, datetime, time import geruecht.controller.databaseController as dc from geruecht.logger import getDebugLogger db = dc.DatabaseController() debug = getDebugLogger() class Base: def getAllJobKinds(self): debug.info("get all jobkinds") retVal = db.getAllJobKinds() debug.debug("jobkinds are {{ {} }}".format(retVal)) return retVal def getJobKind(self, name): debug.info("get jobkinds {{ {} }}".format(name)) retVal = db.getJobKind(name) debug.debug("jobkind is {{ {} }} is {{ {} }}".format(name, retVal)) return retVal def setJobKind(self, name, workgroup=None): debug.info("set jobkind {{ {} }} ".format(name)) retVal = db.setJobKind(name, workgroup) debug.debug( "seted jobkind {{ {} }} is {{ {} }}".format(name, retVal)) return retVal def deleteJobKind(self, jobkind): debug.info("delete jobkind {{ {} }}".format(jobkind)) db.deleteJobKind(jobkind) def updateJobKind(self, jobkind): debug.info("update workgroup {{ {} }}".format(jobkind)) retVal = db.updateJobKind(jobkind) debug.debug("updated jobkind is {{ {} }}".format(retVal)) return retVal def getJobKindDates(self, date): debug.info("get jobkinddates on {{ {} }}".format(date)) retVal = db.getJobKindDates(date) debug.debug("jobkinddates are {{ {} }}".format(retVal)) return retVal def updateJobKindDates(self, jobkindDate): debug.info("update jobkinddate {{ {} }}".format(jobkindDate)) retVal = db.updateJobKindDates(jobkindDate) debug.debug("updated jobkind is {{ {} }}".format(retVal)) return retVal def deleteJobKindDates(self, jobkinddates): debug.info("delete jobkinddates {{ {} }}".format(jobkinddates)) db.deleteJobKindDates(jobkinddates) def setJobKindDates(self, datum, jobkind, maxpersons): debug.info("set jobkinddates with {{ {}, {}, {}, }}".format(datum, jobkind, maxpersons)) retVal = db.setJobKindDates(datum, jobkind, maxpersons) debug.debug("seted jobkinddates is {{ {} }}".format(retVal)) return retVal def controllJobKindDates(self, jobkinddates): debug.info("controll jobkinddates {{ {} }}".format(jobkinddates)) datum = None for jobkinddate in jobkinddates: datum = date(jobkinddate['daydate']['year'], jobkinddate['daydate']['month'], jobkinddate['daydate']['day']) if jobkinddate['id'] == -1: self.setJobKindDates(datum, jobkinddate['job_kind'], jobkinddate['maxpersons']) if jobkinddate['id'] == 0: jobkinddate['id'] = jobkinddate['backupid'] db.deleteAllWorkerWithJobKind(datetime.combine(datum, time(12)), jobkinddate['job_kind']) self.deleteJobKindDates(jobkinddate) if jobkinddate['id'] >= 1: self.updateJobKindDates(jobkinddate) retVal = self.getJobKindDates(datum) if datum != None else [] debug.debug("controlled jobkinddates {{ {} }}".format(retVal)) return retVal def getJobKindDatesFromTo(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 jobkinddate = self.getJobKindDates(startdate) retVal.append(jobkinddate) debug.debug("lock days are {{ {} }}".format(retVal)) return retVal