def plant(): db = DB() action = request.args.get('action') if action == 'read': valveConfigs = db.loadValveConfigs() # print 'READ VALVE CONFIG:' # print valveConfigs response = json.dumps({ 'plant': valveConfigs }) elif action == 'create': jsonValveConfigs = request.form['plant'] valveConfig = json.loads(jsonValveConfigs) # check if valves can be added (system_settings.valve_amount) maxValves = db.getMaxValveCountSetting() actualValves = db.getValveCount() if not maxValves or actualValves < maxValves: # print 'CREATED VALVE CONFIG:' # print valveConfig newRow = db.addValveConfig(valveConfig) if len(newRow): restartJobManager() responseObj = { 'success': 'true', 'plant': newRow } else: responseObj = { 'success': 'false' } else: responseObj = { 'success': 'false', 'message': 'No more entrys to add, maximum entries can be configured in settings.' } response = json.dumps(responseObj) elif action == 'update': jsonValveConfigs = request.form['plant'] valveConfig = json.loads(jsonValveConfigs) # print 'UPDATED VALVE CONFIG:' # print valveConfig success = db.saveValveConfig(valveConfig) if success == True: restartJobManager() responseObj = { 'success': 'true' } else: responseObj = { 'success': 'false', 'message': 'Valve already used by another entry.' } response = json.dumps(responseObj)#{'success': 'false', 'message': }#, 500 #'metaData': { 'messageProperty': 'msg', 'successProperty': 'success' } elif action == 'destroy': jsonValveConfigs = request.form['plant'] valveConfig = json.loads(jsonValveConfigs) # print 'DELETED VALVE CONFIG:' # print valveConfig success = db.deleteValveConfig(valveConfig['id']) restartJobManager() response = json.dumps({ 'success': str(success).lower() }) return response