def post(self, request): """ 修改接口 :param request: :return: """ data=request.data result = self.parameter_check(data) if result: return result data["userUpdate"] = request.user.pk data["params"]="{}" if not "params" in data or not data["params"] else data["params"] try: pro_data = Project.objects.get(id=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code="999995", msg="项目不存在!") pro_data = ProjectSerializer(pro_data) if not pro_data.data["status"]: return JsonResponse(code="999985", msg="该项目已禁用") api_name = ApiInfo.objects.filter(name=data["name"], project=data["project_id"]).exclude(id=data["id"]) if len(api_name): return JsonResponse(code="999997", msg="存在相同名称!") # data["userUpdate"] = request.user result=ApiService.updateApi(data) if result: record_dynamic(project=data["project_id"], _type="修改", operationObject="接口", user=request.user.pk, data="修改接口“%s”" % data["name"]) api_record = ApiOperationHistory(api=ApiInfo.objects.get(id=data['id']), user=User.objects.get(id=request.user.pk), description="修改接口\"%s\"" % data["name"]) api_record.save() return JsonResponse(code="999999", msg="执行成功!") return JsonResponse(code="999996", msg="执行失败!")
def run(self): try: start = time.clock() for apiInfo in self.apiInfoList: if "id" in apiInfo: ApiService.updateApi(apiInfo) else: ApiService.addApi(apiInfo) duration = int(time.clock() - start) print("导入%s分组共%s个接口,耗时%s秒!" % (self.toGroupName, len(self.apiInfoList), duration)) record_dynamic(project=self.projectId, _type="导入", operationObject="接口", user=self.userId, data="导入%s分组共%s个接口,耗时%s秒!" % (self.toGroupName, len(self.apiInfoList), duration)) except: logging.error(traceback.format_exc())