from datetime import date, time, datetime import geruecht.controller.emailController as ec import geruecht.controller.databaseController as dc from geruecht import getDebugLogger db = dc.DatabaseController() debug = getDebugLogger() emailController = ec.EmailController() class Base: def getJobRequests(self, from_user, to_user, date): debug.info("get JobRequests from_user {{ {} }} to_user {{ {} }} on date {{ {} }}".format(from_user, to_user, date)) if from_user is None: retVal = db.getJobRequestsToUser(to_user, date) elif to_user is None: retVal = db.getJobRequestsFromUser(from_user, date) else: raise Exception("from_user {{ {} }} and to_user {{ {} }} are None".format(from_user, to_user)) return retVal def setJobRequests(self, data): debug.info("set new JobRequests data {{ {} }}".format(data)) retVal = [] for jobRequest in data: from_user = jobRequest['from_user'] to_user = jobRequest['to_user'] on_date = date(jobRequest['date']['year'], jobRequest['date']['month'], jobRequest['date']['day']) job_kind = jobRequest['job_kind'] debug.info("set new JobRequest from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}") setJobRequest = db.setJobRequest(from_user, to_user, on_date, job_kind) retVal.append(setJobRequest) emailController.sendMail(db.getUserById(to_user['id']), type='jobtransact', jobtransact=setJobRequest) debug.debug("seted JobRequests are {{ {} }}".format(retVal)) return retVal def updateJobRequests(self, data): debug.info("update JobRequest data {{ {} }}".format(data)) if data['accepted']: self.changeWorker(data['from_user'], data['to_user'], datetime.combine(data['on_date'], time(12))) db.updateAllJobRequest(data) return db.updateJobRequest(data) def deleteJobRequest(self, jobRequest): debug.info("delete JobRequest {{ {} }}".format(jobRequest)) db.deleteJobRequest(jobRequest)