From 7ce8fef278e1f1038c3b1389ee9ebe0bf7a84304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 17 May 2020 21:18:56 +0200 Subject: [PATCH] vorstand can change the group for jobkind --- geruecht/controller/databaseController.py | 9 ++++++--- geruecht/controller/userController.py | 4 ++-- geruecht/vorstand/routes.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/geruecht/controller/databaseController.py b/geruecht/controller/databaseController.py index 8e760c2..59c5b1b 100644 --- a/geruecht/controller/databaseController.py +++ b/geruecht/controller/databaseController.py @@ -705,6 +705,8 @@ class DatabaseController(metaclass=Singleton): 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() @@ -722,16 +724,17 @@ class DatabaseController(metaclass=Singleton): 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): + def setJobKind(self, name, workgroup_id): try: cursor = self.db.connection.cursor() - cursor.execute("insert into job_kind (name) values ('{}')".format(name)) + 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: @@ -742,7 +745,7 @@ class DatabaseController(metaclass=Singleton): def updateJobKind(self, jobkind): try: cursor = self.db.connection.cursor() - cursor.execute("update job_kind set name='{}'where id={}".format(jobkind['name'], jobkind['id'])) + 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: diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index b129317..3e6f605 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -35,9 +35,9 @@ class UserController(metaclass=Singleton): debug.debug("jobkind is {{ {} }} is {{ {} }}".format(name, retVal)) return retVal - def setJobKind(self, name): + def setJobKind(self, name, workgroup=None): debug.info("set jobkind {{ {} }} ".format(name)) - retVal = db.setJobKind(name) + retVal = db.setJobKind(name, workgroup) debug.debug( "seted jobkind {{ {} }} is {{ {} }}".format(name, retVal)) return retVal diff --git a/geruecht/vorstand/routes.py b/geruecht/vorstand/routes.py index 4e99868..b098fff 100644 --- a/geruecht/vorstand/routes.py +++ b/geruecht/vorstand/routes.py @@ -308,7 +308,10 @@ def _JobKinds(**kwargs): data = request.get_json() if request.method == 'PUT': name = data['name'] - retVal = userController.setJobKind(name) + workgroup = None + if 'workgroup' in data: + workgroup = data['workgroup'] + retVal = userController.setJobKind(name, workgroup) debug.debug("return {{ {} }}".format(retVal)) if request.method == 'POST': retVal = userController.updateJobKind(data)