flaschengeist/geruecht/controller/databaseController/dbJobKindController.py

132 lines
6.1 KiB
Python
Raw Normal View History

import traceback
from geruecht.exceptions import DatabaseExecption
class Base:
def getAllJobKinds(self):
try:
cursor = self.db.connection.cursor()
cursor.execute('select * from job_kind')
list = cursor.fetchall()
for item in list:
item['workgroup'] = self.getWorkgroup(item['workgroup']) if item['workgroup'] != None else None
return list
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def getJobKind(self, name):
try:
cursor = self.db.connection.cursor()
if type(name) == str:
sql = "select * from job_kind where name='{}'".format(name)
elif type(name) == int:
sql = 'select * from job_kind where id={}'.format(name)
else:
raise DatabaseExecption("name as no type int or str. name={}, type={}".format(name, type(name)))
cursor.execute(sql)
retVal = cursor.fetchone()
retVal['workgroup'] = self.getWorkgroup(retVal['workgroup']) if retVal['workgroup'] != None else None
return retVal
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def setJobKind(self, name, workgroup_id):
try:
cursor = self.db.connection.cursor()
cursor.execute("insert into job_kind (name, workgroup) values ('{}', {})".format(name, workgroup_id if workgroup_id != None else 'NULL'))
self.db.connection.commit()
return self.getJobKind(name)
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def updateJobKind(self, jobkind):
try:
cursor = self.db.connection.cursor()
cursor.execute("update job_kind set name='{}', workgroup={} where id={}".format(jobkind['name'], jobkind['workgroup']['id'] if jobkind['workgroup'] != None else 'NULL', jobkind['id']))
self.db.connection.commit()
return self.getJobKind(jobkind['id'])
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def deleteJobKind(self, jobkind):
try:
cursor = self.db.connection.cursor()
cursor.execute("delete from job_kind where id={}".format(jobkind['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def setJobKindDates(self, date, jobkind, maxpersons):
try:
cursor = self.db.connection.cursor()
cursor.execute("insert into job_kind_dates (daydate, job_kind, maxpersons) values ('{}', {}, {})".format(date, jobkind['id'] if jobkind != None else 'NULL', maxpersons))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def updateJobKindDates(self, jobkindDate):
try:
cursor = self.db.connection.cursor()
cursor.execute("update job_kind_dates set job_kind={}, maxpersons='{}' where id={}".format(jobkindDate['job_kind']['id'] if jobkindDate['job_kind'] != None else 'NULL', jobkindDate['maxpersons'], jobkindDate['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def getJobKindDates(self, date):
try:
cursor = self.db.connection.cursor()
cursor.execute("select * from job_kind_dates where daydate='{}'".format(date))
list = cursor.fetchall()
for item in list:
item['job_kind'] = self.getJobKind(item['job_kind']) if item['job_kind'] != None else None
item['daydate'] = {'year': item['daydate'].year, 'month': item['daydate'].month, 'day': item['daydate'].day}
return list
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
2020-06-04 19:20:38 +00:00
def getJobKindDate(self, date, job_kind):
try:
cursor = self.db.connection.cursor()
cursor.execute("select * from job_kind_dates where daydate='{}' and job_kind={}".format(date, job_kind['id']))
item = cursor.fetchone()
if item:
item['job_kind'] = self.getJobKind(item['job_kind']) if item['job_kind'] != None else None
item['daydate'] = {'year': item['daydate'].year, 'month': item['daydate'].month, 'day': item['daydate'].day}
else:
item = {
'job_kind': self.getJobKind(1),
'daydate': {'year': date.year, 'month': date.month, 'day': date.day},
'maxpersons': 2
}
return item
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))
def deleteJobKindDates(self, jobkinddates):
try:
cursor = self.db.connection.cursor()
cursor.execute("delete from job_kind_dates where id={}".format(jobkinddates['id']))
self.db.connection.commit()
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went worng with Databes: {}".format(err))