コード例 #1
0
def checkPostAction(object, data, suppostAction):
    token = data.pop("token", None)
    if token:
        if not checkSession(token):
            return packOutput({}, "401", "Token authority failed")
    action = data.pop("action", None)
    if action is None:
        return packOutput({}, code="400", errorInfo='action required')
    if action not in suppostAction:
        return packOutput({}, code="400", errorInfo='unsupported action')

    # result = getattr(object, suppostAction[action])(data)
    # return packOutput(result)
    try:
        result = getattr(object, suppostAction[action])(data)
        return packOutput(result)
    except Exception as e:
        exc_traceback = sys.exc_info()[2]
        error_trace = traceback.format_exc(exc_traceback)
        error_args = e.args
        if len(error_args) == 2:
            code = error_args[0]
            error_info = str(error_args[1])
        else:
            code = "500"
            error_info = str(e)
        return packOutput({
            "errorInfo": str(error_info),
            "rescode": code
        },
                          code=code,
                          errorInfo=error_trace)
コード例 #2
0
ファイル: queueData.py プロジェクト: fanchunke1991/HQMS
    def POST(self, name):
        webData = json.loads(web.data())
        action = webData["action"]

        if "token" in webData:
            token = webData["token"]
            if checkSession(token) == False:
                return packOutput({}, "401", "Tocken authority failed")

        if action == "getListWaiting":
            ret = self.getQueueVisitor(webData)
            jsonData = {"num": len(ret), "list": []}
            for item in ret:
                visitor = {}
                visitor["id"] = item["id"]
                visitor["name"] = item["name"]
                visitor["status"] = item["status"]
                visitor["originScore"] = item["originScore"]
                visitor["finalScore"] = item["finalScore"]
                visitor["originLevel"] = item["originLevel"]
                jsonData["list"].append(visitor)
            return packOutput(jsonData)

        elif action == "getListUnactive":
            pass

        elif action == "getListOver":
            pass

        else:
            return packOutput({}, "500", "unsupport action")
コード例 #3
0
    def POST(self, inputData):
        data = json.loads(web.data())

        token = data.pop("token", None)
        if token:
            if checkSession(token) == False:
                return packOutput({}, "401", "Token authority failed")
        action = data.pop("action", None)
        if action is None:
            return packOutput({}, code='400', errorInfo='action required')
        if action not in self.support_action:
            return packOutput({}, code='400', errorInfo='unsupported action')

        try:
            result = getattr(self, self.support_action[action])(data)
            return packOutput(result)
        except Exception as e:
            exc_traceback = sys.exc_info()[2]
            errorInfo = traceback.format_exc(exc_traceback)
            return packOutput({
                "errorInfo": str(e),
                "rescode": "500"
            },
                              code='500',
                              errorInfo=errorInfo)
コード例 #4
0
    def POST(self, name):

        webData = json.loads(web.data())
        action = webData["action"]
        if "token" in webData:
            token = webData["token"]
            if checkSession(token) == False:
                return packOutput({}, "401", "Token authority failed")

        if action == "getList":
            list = self.getList(webData)
            num = len(list)
            resultJson = {"num": num, "list": []}
            for item in list:
                caller = item.copy()
                resultJson["list"].append(caller)
            return packOutput(resultJson)

        elif action == "getInfo":
            caller = self.getInfo(webData)
            return packOutput(caller)

        elif action == "add":
            ret = self.add(webData)
            return packOutput({})

        elif action == "edit":
            id = self.edit(webData)
            return packOutput({})

        elif action == "delete":
            ret = self.delete(webData)
            if ret == -1:
                resultJson = {"result": "failed"}
            else:
                resultJson = {"result": "success"}
            return packOutput(resultJson)

        elif action == "setWorkerStatus":
            ret = self.setWorkerStatus(webData)
            if ret == -1:
                resultJson = {"result": "failed"}
            else:
                resultJson = {"result": "success"}
            return packOutput(resultJson)

        elif action == "checkIP":
            try:
                result = self.checkIP(webData)
                return packOutput(result)
            except Exception as e:
                return packOutput({}, code=500, errorInfo=str(e))

        else:
            return packOutput({}, "500", "unsupport action")
コード例 #5
0
    def POST(self, name):
        webData = json.loads(web.data())
        action = webData["action"]
        if "token" in webData:
            token = webData["token"]
            if checkSession(token) == False:
                return packOutput({}, "401", "Tocken authority failed")

        if action == "getList":
            slist = self.getList()
            num = len(slist)
            if num == -1:
                return packOutput({}, "500", "getStationList Error")
            else:
                resultJson = {"stationNum": num, "stationList": []}
                for item in slist:
                    station = {}
                    station['id'] = item["id"]
                    station['name'] = item["name"]
                    resultJson['stationList'].append(station)
                print " get stationList func ok ,station num " + str(num)
                return packOutput(resultJson)

        elif action == "getInfo":
            print(" Controller get stationInfo ")
            req = json.loads(web.data())
            stationID = req["stationID"]

            ret = self.getInfo({"id": stationID})

            if ret == {}:
                return packOutput({}, "500", "getStationInfo Error")
            else:
                return packOutput(ret)

        elif action == "add":
            print(" Controller  Add station ")
            addObj = json.loads(web.data())
            try:
                id = self.add(addObj)
                resultJson = {"stationID": id}
                return packOutput(resultJson)
            except Exception, e:
                print Exception, ":", e
                return packOutput({}, "500", "Add station error : " + str(e))
コード例 #6
0
    def POST(self, name):

        webData = json.loads(web.data())
        action = webData["action"]
        if "token" in webData:
            token = webData["token"]
            if checkSession(token) == False:
                return packOutput({}, "401", "Tocken authority failed")

        if action == "getList":
            list = self.getList(webData)
            num = len(list)
            resultJson = {"workerNum": num, "workerList": []}
            for item in list:
                worker = item.copy()
                del worker["callerList"]
                resultJson["workerList"].append(worker)
            return packOutput(resultJson)

        elif action == "getInfo":
            worker = self.getInfo(webData)
            return packOutput(worker)

        elif action == "import":
            self.imports(webData)
            return packOutput({})

        elif action == "add":
            id = self.addWorker(webData)
            return packOutput({})

        elif action == "del":
            ret = self.delWorker(webData)
            if ret == -1:
                resultJson = {"result": "failed"}
            else:
                resultJson = {"result": "success"}
            return packOutput(resultJson)

        elif action == "edit":
            id = self.editWorker(webData)
            return packOutput({})

        elif action == "testSource":
            ret = self.testImportSource(webData)
            if ret:
                resultJson = {"result": "success"}
            else:
                resultJson = {"result": "failed"}
            return packOutput(resultJson)

        elif action == "testSourceConfig":
            ret = self.testImportSourceConfig(webData)
            sql = self.getAliasSql(webData)
            if ret:
                resultJson = {"result": "success", "sql": sql}
            else:
                resultJson = {"result": "failed", "sql": sql}
            return packOutput(resultJson)

        elif action == "checkID":
            ret = self.checkConflict(webData)
            resultJson = {"conflict": ret}
            return packOutput(resultJson)

        else:
            return packOutput({}, "500", "unsupport action")
コード例 #7
0
    def POST(self, name):

        webData = json.loads(web.data())
        action = webData["action"]
        if "token" in webData:
            token = webData["token"]
            if checkSession(token) == False:
                return packOutput({}, "401", "Tocken authority failed")

        if action == "getList":
            list = self.getList(webData)
            num = len(list)
            resultJson = {"num": num, "list": []}
            for item in list:
                queue = item.copy()
                queue["workerLimit"] = str2List(queue["workerLimit"])
                resultJson["list"].append(queue)
            return packOutput(resultJson)

        elif action == "getInfo":
            queueInfo = self.getInfo(webData)
            queueInfo["workerLimit"] = str2List(queueInfo["workerLimit"])
            return packOutput(queueInfo)

        elif action == "add":
            webData["workerLimit"] = list2Str(webData["workerLimit"])
            ret = self.add(webData)
            return packOutput({})

        elif action == "edit":
            webData["workerLimit"] = list2Str(webData["workerLimit"])
            id = self.edit(webData)
            return packOutput({})

        elif action == "delete":
            ret = self.delete(webData)
            if ret == -1:
                resultJson = {"result": "failed"}
            else:
                resultJson = {"result": "success"}
            return packOutput(resultJson)

        elif action == "getSourceQueueList":
            ret = self.getSourceQueueList(webData)
            jsonData = {"num": len(ret), "list": ret}
            return packOutput(jsonData)

        elif action == "getSceneSupportList":
            ret = self.getSceneSupportList(webData)
            list = []
            for item in ret:
                list.append(item)
            jsonData = {"num": len(ret), "list": list}
            return packOutput(jsonData)

        elif action == "getAvgWaitTime":
            try:
                result = self.getAvgWaitTime(webData)
                return packOutput(result)
            except Exception as errorInfo:
                return packOutput({}, code="400", errorInfo=str(errorInfo))

        else:
            return packOutput({}, "500", "unsupport action")