def demo(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) response['message'] = '创建成功' return JsonResponse(response) if request.method == "PUT": data = body_to_dict(request) response['message'] = '更新成功' return JsonResponse(response) if request.method == "DELETE": data = body_to_dict(request) response['message'] = '删除成功' return JsonResponse(response) if request.method == "GET": event = request.GET.get('event') result = models_logs.get_logs(user_id, event) if result: response['data'] = result return JsonResponse(response) response['code'] = 401 response['message'] = '未找到' return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def debugtalk(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) result = models_tools.create_debugtalk(data, user_id) response['message'] = '创建成功' response['extra'] = result return JsonResponse(response) if request.method == "PUT": data = body_to_dict(request) result = models_tools.update_debugtalk(data, user_id) if result: response['message'] = '更新成功' return JsonResponse(response) response['code'] = 401 response['message'] = 'debugtalk不存在' return JsonResponse(response) if request.method == 'GET': id = request.GET.get('id') result = models_tools.get_debugtalk(id) if result: response['extra'] = result return JsonResponse(response) response['code'] = 401 response['message'] = 'debugtalk不存在' return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def kind(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) models_nav.create_kind(data) response['message'] = '创建成功' return JsonResponse(response) if request.method == "PUT": data = body_to_dict(request) result = models_nav.update_kind(data) if result: response['message'] = '更新成功' return JsonResponse(response) response['code'] = 401 response['message'] = '未找到' return JsonResponse(response) if request.method == "DELETE": data = body_to_dict(request) models_nav.delete_kind(data) response['message'] = '成功' return JsonResponse(response) if request.method == "GET": result = models_nav.get_kinds() response['data'] = result return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def tool(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) result = models_tools.create_tool(data, user_id) if result: response['message'] = '创建成功' return JsonResponse(response) response['code'] = 401 response['message'] = "虚拟路由已存在,请重新定义。" return JsonResponse(response) if request.method == "GET": tool_id = request.GET.get('tool_id', None) result = models_tools.get_tool(tool_id) if result: response['extra'] = result return JsonResponse(response) response['code'] = 402 response['message'] = '未找到' return JsonResponse(response) if request.method == "PUT": data = body_to_dict(request) result = models_tools.update_tool(data, user_id) if result: response['message'] = '更新成功' return JsonResponse(response) response['code'] = 403 response['message'] = '未找到' return JsonResponse(response) if request.method == "DELETE": data = body_to_dict(request) result = models_tools.delete_tool(data.get('id')) if result: response['message'] = '删除成功' return JsonResponse(response) response['code'] = 405 response['message'] = '未找到' return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def project(request): response = response_json() try: if request.method == "GET": project_list = models_project.get_all_class() response['data'] = project_list return JsonResponse(response) if request.method == "POST": data = body_to_dict(request) result = models_project.create_class(data) if result: response['message'] = '创建成功' return JsonResponse(response) response['code'] = 401 response['message'] = "定义的URL已存在" return JsonResponse(response) if request.method == "PUT": data = body_to_dict(request) result = models_project.update_class(data) if result: response['extra'] = result return JsonResponse(response) response['code'] = 402 response['message'] = "未找到" return JsonResponse(response) if request.method == "DELETE": data = body_to_dict(request) result = models_project.delete_class(data) if result: response['message'] = "删除成功" return JsonResponse(response) response['code'] = 403 response['message'] = "未找到" return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def launch(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) result = models_run.run(data, user_id) if result: response['data'] = result return JsonResponse(response) response['message'] = '无响应信息' return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def wisdom(request): response = response_json() try: if request.method == "POST": data = body_to_dict(request) models_wisdom.create_wisdom(data) response['message'] = '创建成功' return JsonResponse(response) if request.method == "GET": result = models_wisdom.get_wisdom() response['extra'] = result return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)
def visit(request): response = response_json() user_id = request.headers.get('uid') try: if request.method == "POST": data = body_to_dict(request) models_visit.create_visit(data, user_id) response['message'] = '创建成功' return JsonResponse(response) if request.method == "GET": tool_id = request.GET.get('tool_id', None) project_id = request.GET.get('project_id', None) user_id = request.headers.get('uid', None) result = models_visit.get_visit(tool_id=tool_id, project_id=project_id, user_id=user_id) response['extra'] = {'count': result} return JsonResponse(response) except: response['code'] = 500 response['message'] = traceback.format_exc() return JsonResponse(response)