vorstand can change the group for jobkind

This commit is contained in:
Tim Gröger 2020-05-17 21:18:56 +02:00
parent 04d6254262
commit 7ce8fef278
3 changed files with 12 additions and 6 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)