41 lines
1.8 KiB
Python
41 lines
1.8 KiB
Python
from datetime import date, time, datetime
|
|
|
|
import geruecht.controller.databaseController as dc
|
|
from geruecht import getDebugLogger
|
|
|
|
db = dc.DatabaseController()
|
|
debug = getDebugLogger()
|
|
|
|
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'])
|
|
debug.info("set new JobRequest from_user {{ {} }}, to_user {{ {} }}, on_date {{ {} }}")
|
|
retVal.append(db.setJobRequest(from_user, to_user, on_date))
|
|
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) |