vorstand can create, edit or delete job_kinds
This commit is contained in:
parent
41b6a2e530
commit
04d6254262
|
@ -700,6 +700,66 @@ class DatabaseController(metaclass=Singleton):
|
|||
self.db.connection.rollback()
|
||||
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
|
||||
|
||||
def getAllJobKinds(self):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute('select * from job_kind')
|
||||
list = cursor.fetchall()
|
||||
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()
|
||||
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):
|
||||
try:
|
||||
cursor = self.db.connection.cursor()
|
||||
cursor.execute("insert into job_kind (name) values ('{}')".format(name))
|
||||
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='{}'where id={}".format(jobkind['name'], 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))
|
||||
|
||||
if __name__ == '__main__':
|
||||
db = DatabaseController()
|
||||
user = db.getUser('jhille')
|
||||
|
|
|
@ -23,6 +23,35 @@ class UserController(metaclass=Singleton):
|
|||
debug.debug("init UserController")
|
||||
pass
|
||||
|
||||
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):
|
||||
debug.info("set jobkind {{ {} }} ".format(name))
|
||||
retVal = db.setJobKind(name)
|
||||
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 updateWorkgroupsOfUser(self, user, workgroups):
|
||||
debug.info("update workgroups {{ {} }} of user {{ {} }}".format(workgroups, user))
|
||||
db.deleteWorkgroupsOfUser(user)
|
||||
|
|
|
@ -272,6 +272,65 @@ def _deleteWorkgroup(**kwargs):
|
|||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/getAllJobKinds", methods=['GET'])
|
||||
@login_required(bar=True)
|
||||
def _getAllJobKinds(**kwargs):
|
||||
try:
|
||||
debug.info("get all jobkinds")
|
||||
retVal = userController.getAllJobKinds()
|
||||
debug.info("return all jobkinds {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get all workgroups.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/getJobKind", methods=['POST'])
|
||||
@login_required(bar=True)
|
||||
def _getJobKinds(**kwargs):
|
||||
try:
|
||||
debug.info("get jobkind")
|
||||
data = request.get_json()
|
||||
name = data['name']
|
||||
debug.info("get jobkind {{ {} }}".format(name))
|
||||
retVal = userController.getJobKind(name)
|
||||
debug.info(
|
||||
"return workgroup {{ {} }} : {{ {} }}".format(name, retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.warning("exception in get workgroup.", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/JobKind", methods=['POST', 'PUT', 'DELETE'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
def _JobKinds(**kwargs):
|
||||
debug.info("/sm/JobKind")
|
||||
try:
|
||||
data = request.get_json()
|
||||
if request.method == 'PUT':
|
||||
name = data['name']
|
||||
retVal = userController.setJobKind(name)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
if request.method == 'POST':
|
||||
retVal = userController.updateJobKind(data)
|
||||
debug.debug("return {{ {} }}".format(retVal))
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/deleteJobKind", methods=['POST'])
|
||||
@login_required(groups=[VORSTAND])
|
||||
def _deleteJobKind(**kwargs):
|
||||
try:
|
||||
data = request.get_json()
|
||||
debug.info("/sm/deleteJobKind")
|
||||
userController.deleteJobKind(data)
|
||||
retVal = {"ok": "ok"}
|
||||
debug.debug("return ok")
|
||||
return jsonify(retVal)
|
||||
except Exception as err:
|
||||
debug.debug("exception", exc_info=True)
|
||||
return jsonify({"error": str(err)}), 500
|
||||
|
||||
@vorstand.route("/sm/lockDay", methods=['POST'])
|
||||
@login_required(groups=[MONEY, GASTRO, VORSTAND])
|
||||
|
|
Loading…
Reference in New Issue