def enable_host(request): """ 启用host project_id 项目ID host_id 地址ID :return: """ project_id = request.POST.get('project_id') host_id = request.POST.get('host_id') if not project_id.isdecimal() or not host_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obi = GlobalHost.objects.filter(id=host_id, project=project_id) if obi: obi.update(status=True) record = ProjectDynamic(project=Project.objects.get(id=project_id), type='启用', operationObject='HOST', user=User.objects.get(id=request.user.pk), description='启用HOST“%s”' % obi[0].name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.host_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def record_dynamic(project_id, _type, _object, desc): """ 记录动态 :param project_id: 项目ID :param _type: 操作类型 :param _object: 操作对象 :param desc: 描述 :return: """ record = ProjectDynamic(project=Project.objects.get(id=project_id), type=_type, operationObject=_object, user=User.objects.get(id=1), description=desc) record.save()
def update_project(request): """ 修改项目 project_id: 项目唯一id name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ project_id = request.POST.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get('name') version = request.POST.get('v') _type = request.POST.get('type') description = request.POST.get('description') if _type in ['Web', 'App']: obj = Project.objects.filter(id=project_id) if obj: obi = Project.objects.filter(name=name).exclude(id=project_id) if len(obi) == 0: obj.update(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) record = ProjectDynamic( project=Project.objects.get(id=project_id), type='修改', operationObject='项目', user=User.objects.get(id=request.user.pk), description='修改项目“%s”' % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def update_project(request): """ 修改项目 project_id: 项目唯一id name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ project_id = request.POST.get("project_id") if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get("name") version = request.POST.get("v") _type = request.POST.get("type") description = request.POST.get("description") if _type in ["Web", "App"]: obj = Project.objects.filter(id=project_id) if obj: obi = Project.objects.filter(name=name).exclude(id=project_id) if len(obi) == 0: obj.update(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) record = ProjectDynamic( project=Project.objects.get(id=project_id), type="修改", operationObject="项目", user=User.objects.get(id=request.user.pk), description="修改项目“%s”" % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def add_project(request): """ 新增项目 name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ name = request.POST.get('name') version = request.POST.get('v') _type = request.POST.get('type') description = request.POST.get('description') if _type in ['Web', 'App']: obj = Project.objects.filter(name=name) if len(obj) == 0: with transaction.atomic(): project = Project(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) project.save() ProjectMember( permissionType='admin', project=Project.objects.get(id=project.pk), user=User.objects.get(id=request.user.pk)).save() record = ProjectDynamic( project=Project.objects.get(id=project.pk), type='创建', operationObject='项目', user=User.objects.get(id=request.user.pk), description='创建项目“%s”' % name) record.save() return JsonResponse(data={'project_id': project.pk}, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def add_project(request): """ 新增项目 name: 项目名称 v: 项目版本 type: 项目类型 description: 项目描述 :return: """ name = request.POST.get("name") version = request.POST.get("v") _type = request.POST.get("type") description = request.POST.get("description") if _type in ["Web", "App"]: obj = Project.objects.filter(name=name) if len(obj) == 0: with transaction.atomic(): project = Project(name=name, version=version, type=_type, description=description, user=User.objects.get(id=request.user.pk)) project.save() ProjectMember( permissionType="admin", project=Project.objects.get(id=project.pk), user=User.objects.get(id=request.user.pk)).save() record = ProjectDynamic( project=Project.objects.get(id=project.pk), type="创建", operationObject="项目", user=User.objects.get(id=request.user.pk), description="创建项目“%s”" % name) record.save() return JsonResponse(data={"project_id": project.pk}, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong())
def update_host(request): """ 修改host project_id 项目id host_id 地址ID name 地址名称 host 地址域名 description 描述 :return: """ project_id = request.POST.get('project_id') host_id = request.POST.get('host_id') if not host_id.isdecimal() or not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get('name') host = request.POST.get('host') desc = request.POST.get('description') obj = Project.objects.filter(id=project_id) if obj: obi = GlobalHost.objects.filter(id=host_id, project=project_id) if obi: obm = GlobalHost.objects.filter(name=name).exclude(id=host_id) if len(obm) == 0: obi.update(project=Project.objects.get(id=project_id), name=name, host=host, description=desc) record = ProjectDynamic( project=Project.objects.get(id=project_id), type='修改', operationObject='HOST', user=User.objects.get(id=request.user.pk), description='修改HOST“%s”' % name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse( code_msg=GlobalStatusCode.name_repetition()) else: return JsonResponse(code_msg=GlobalStatusCode.host_not_exist()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def disable_project(request): """ 禁用项目 project_id 项目ID :return: """ project_id = request.POST.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) obj = Project.objects.filter(id=project_id) if obj: obj.update(status=False) record = ProjectDynamic(project=Project.objects.get(id=project_id), type='禁用', operationObject='项目', user=User.objects.get(id=request.user.pk), description='禁用项目“%s”' % obj[0].name) record.save() return JsonResponse(code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())
def add_host(request): """ 新增host project_id 项目ID name host名称 host host地址 description host描述 :return: """ project_id = request.POST.get('project_id') if not project_id.isdecimal(): return JsonResponse(code_msg=GlobalStatusCode.parameter_wrong()) name = request.POST.get('name') host = request.POST.get('host') desc = request.POST.get('description') obj = Project.objects.filter(id=project_id) if obj: obi = GlobalHost.objects.filter(name=name, project=project_id) if obi: return JsonResponse(code_msg=GlobalStatusCode.name_repetition()) else: hosts = GlobalHost(project=Project.objects.get(id=project_id), name=name, host=host, description=desc) hosts.save() record = ProjectDynamic(project=Project.objects.get(id=project_id), type='新增', operationObject='HOST', user=User.objects.get(id=request.user.pk), description='新增HOST“%s”' % name) record.save() return JsonResponse(data={'host_id': hosts.pk}, code_msg=GlobalStatusCode.success()) else: return JsonResponse(code_msg=GlobalStatusCode.project_not_exist())