def post(self, request): """ 新增接口分组 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result try: obj = Project.objects.get(id=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code="999995", msg="项目不存在!") pro_data = ProjectSerializer(obj) if not pro_data.data["status"]: return JsonResponse(code="999985", msg="该项目已禁用") serializer = ApiGroupLevelFirstDeserializer(data=data) if serializer.is_valid(): serializer.save(project=obj) else: return JsonResponse(code="999998", msg="失败!") record_dynamic(project=serializer.data.get("id"), _type="添加", operationObject="接口分组", user=request.user.pk, data="新增接口分组“%s”" % data["name"]) return JsonResponse(data={ "group_id": serializer.data.get("id") }, code="999999", msg="成功!")
def post(self, request): """ 修改接口分组名称 :param request: :return: """ data = JSONParser().parse(request) result = self.parameter_check(data) if result: return result try: pro_data = Project.objects.get(id=data["project_id"]) if not request.user.is_superuser and pro_data.user.is_superuser: return JsonResponse(code="999983", msg="无操作权限!") except ObjectDoesNotExist: return JsonResponse(code="999995", msg="项目不存在!") pro_data = ProjectSerializer(pro_data) if not pro_data.data["status"]: return JsonResponse(code="999985", msg="该项目已禁用") try: obj = ApiGroupLevelFirst.objects.get(id=data["id"], project=data["project_id"]) except ObjectDoesNotExist: return JsonResponse(code="999991", msg="分组不存在!") serializer = ApiGroupLevelFirstDeserializer(data=data) if serializer.is_valid(): serializer.update(instance=obj, validated_data=data) else: return JsonResponse(code="999998", msg="失败!") record_dynamic(project=serializer.data.get("id"), _type="修改", operationObject="接口分组", user=request.user.pk, data="修改接口分组“%s”" % data["name"]) return JsonResponse(code="999999", msg="成功!")