2020-05-22 19:55:14 +00:00
|
|
|
from ..mainController import Singleton
|
|
|
|
from geruecht import db
|
2020-06-04 21:03:39 +00:00
|
|
|
from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController
|
2020-05-22 19:55:14 +00:00
|
|
|
from geruecht.exceptions import DatabaseExecption
|
|
|
|
import traceback
|
|
|
|
from MySQLdb._exceptions import IntegrityError
|
|
|
|
|
2020-05-27 10:10:51 +00:00
|
|
|
class DatabaseController(dbUserController.Base,
|
|
|
|
dbCreditListController.Base,
|
|
|
|
dbWorkerController.Base,
|
|
|
|
dbWorkgroupController.Base,
|
|
|
|
dbPricelistController.Base,
|
|
|
|
dbJobKindController.Base,
|
|
|
|
dbJobInviteController.Base,
|
2020-06-02 21:24:17 +00:00
|
|
|
dbJobRequesController.Base,
|
2020-06-04 21:03:39 +00:00
|
|
|
dbAccessTokenController.Base,
|
2020-05-27 10:10:51 +00:00
|
|
|
metaclass=Singleton):
|
2020-05-22 19:55:14 +00:00
|
|
|
'''
|
|
|
|
DatabaesController
|
|
|
|
|
|
|
|
Connect to the Database and execute sql-executions
|
|
|
|
'''
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.db = db
|
|
|
|
|
|
|
|
def getLockedDay(self, date):
|
|
|
|
try:
|
|
|
|
cursor = self.db.connection.cursor()
|
|
|
|
cursor.execute("select * from locked_days where daydate='{}'".format(date))
|
|
|
|
data = cursor.fetchone()
|
|
|
|
return data
|
|
|
|
except Exception as err:
|
|
|
|
traceback.print_exc()
|
|
|
|
self.db.connection.rollback()
|
|
|
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
|
|
|
|
|
|
def setLockedDay(self, date, locked, hard=False):
|
|
|
|
try:
|
|
|
|
cursor = self.db.connection.cursor()
|
|
|
|
sql = "insert into locked_days (daydate, locked) VALUES ('{}', {})".format(date, locked)
|
|
|
|
cursor.execute(sql)
|
|
|
|
self.db.connection.commit()
|
|
|
|
return self.getLockedDay(date)
|
|
|
|
except IntegrityError as err:
|
|
|
|
self.db.connection.rollback()
|
|
|
|
try:
|
|
|
|
exists = self.getLockedDay(date)
|
|
|
|
if hard:
|
|
|
|
sql = "update locked_days set locked={} where id={}".format(locked, exists['id'])
|
|
|
|
else:
|
|
|
|
sql = False
|
|
|
|
if sql:
|
|
|
|
cursor.execute(sql)
|
|
|
|
self.db.connection.commit()
|
|
|
|
return self.getLockedDay(date)
|
|
|
|
except Exception as err:
|
|
|
|
traceback.print_exc()
|
|
|
|
self.db.connection.rollback()
|
|
|
|
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
|
|
|
except Exception as err:
|
|
|
|
traceback.print_exc()
|
|
|
|
self.db.connection.rollback()
|
|
|
|
raise DatabaseExecption("Something went worng with Datatabase: {}".format(err))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
db = DatabaseController()
|
|
|
|
user = db.getUser('jhille')
|
|
|
|
db.getCreditListFromUser(user, year=2018)
|