Пример #1
0
    def get(self, request, *args, **kwargs):
        """
        列出db申请账号
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            if request.user.is_superuser:
                obj_db_account_list = DatabaseRecord.objects.filter(Q(status=2)).order_by('-id')[:8]
                paginator = StandardResultsSetPagination()
                page_db_account_list = paginator.paginate_queryset(obj_db_account_list, self.request, view=self)
                serializer_db_account_info = DbAccountRecordrListModelSerializers(page_db_account_list, many=True)
                page_db_account_record = paginator.get_paginated_response(serializer_db_account_info.data)
                return Response(page_db_account_record.data)
            else:
                obj_db_account_list = DatabaseRecord.objects.filter(Q(applicant=request.user.name)).order_by('-id')[:8]
                paginator = StandardResultsSetPagination()
                page_db_account_list = paginator.paginate_queryset(obj_db_account_list, self.request, view=self)
                serializer_db_account_info = DbAccountRecordrListModelSerializers(page_db_account_list, many=True)
                page_db_account_record = paginator.get_paginated_response(serializer_db_account_info.data)
                return Response(page_db_account_record.data)

        except BaseException as e:
            logger.error('系统出现异常: %s' % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            }, status=status.HTTP_500_INTERNAL_SERVER_ERROR, json_dumps_params={'ensure_ascii': False})
Пример #2
0
    def get(self, request, *args, **kwargs):
        """
        /api/v1/project/query
        :param request:
        :param args:
        :param kwargs:
        :return:
        """

        try:
            keywords = request.GET.get('keywords', None)
            if keywords is not None:
                keywords = keywords.strip()
                query_project = Project.objects.filter(title__icontains=keywords).order_by('id')
                paginator = StandardResultsSetPagination()
                project_list = paginator.paginate_queryset(query_project, self.request, view=self)
                serializer_project_info = ProjectModelSerializers(project_list, many=True)
                project_page = paginator.get_paginated_response(serializer_project_info.data)
                return Response(project_page.data)

            query_project = Project.objects.all().order_by('id')
            paginator = StandardResultsSetPagination()
            project_list = paginator.paginate_queryset(query_project, self.request, view=self)
            serializer_project_info = ProjectModelSerializers(project_list, many=True)
            project_page = paginator.get_paginated_response(serializer_project_info.data)
            return Response(project_page.data)

        except BaseException:
            logger.error('系统异常 %s' % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            }, status=status.HTTP_500_INTERNAL_SERVER_ERROR, json_dumps_params={'ensure_ascii': False})
Пример #3
0
    def get(self, request, *args, **kwargs):
        """
        获取用户信息
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            if request.user.is_superuser:
                query_user = UserInfo.objects.all()
                paginator = StandardResultsSetPagination()
                query_users = paginator.paginate_queryset(query_user, self.request, view=self)
                serializer_user_info = UserInfoSerializer(query_users, many=True)
                page_ser = paginator.get_paginated_response(serializer_user_info.data)
                return Response(page_ser.data)

            else:
                query_user = UserInfo.objects.filter(name=request.user.name)
                paginator = StandardResultsSetPagination()
                query_users = paginator.paginate_queryset(query_user, self.request, view=self)
                serializer_user_info = UserInfoSerializer(query_users, many=True)
                page_ser = paginator.get_paginated_response(serializer_user_info.data)
                return Response(page_ser.data)

        except BaseException as e:
            logger.error("获取用户信息失败: %s" % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": 1010,
                "msg": "获取用户信息失败, 系统遇到未知错误!",
                "data": "null"
            }, json_dumps_params={'ensure_ascii': False})
Пример #4
0
    def get(self, request, *args, **kwargs):
        """
        获取虚拟主机信息
        :param request:
        :param args:
        :param kwargs:
        :return:
        """

        try:
            keywords = request.GET.get('keywords', None)
            if keywords is not None:
                keywords = keywords.strip()
                query_host = VirtualHost.objects.filter(
                    Q(internet_port__icontains=keywords)
                    | Q(upstream_name__icontains=keywords)
                    | Q(forward_address__icontains=keywords)
                    | Q(creator_name__icontains=keywords)).order_by('id')
                paginator = StandardResultsSetPagination()
                page_nginx_list = paginator.paginate_queryset(query_host,
                                                              self.request,
                                                              view=self)
                serializer_nginx_info = NginxListModelSerializers(
                    page_nginx_list, many=True)
                page_nginx = paginator.get_paginated_response(
                    serializer_nginx_info.data)
                return Response(page_nginx.data)

            obj_nginx_list = VirtualHost.objects.all().order_by('-id')
            paginator = StandardResultsSetPagination()
            page_nginx_list = paginator.paginate_queryset(obj_nginx_list,
                                                          self.request,
                                                          view=self)
            serializer_nginx_info = NginxListModelSerializers(page_nginx_list,
                                                              many=True)
            page_nginx = paginator.get_paginated_response(
                serializer_nginx_info.data)
            return Response(page_nginx.data)

        except BaseException as e:
            logger.error('获取虚拟主机异常, 异常原因: %s' % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": e
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #5
0
    def post(self, request, *args, **kwargs):
        """
        根据部署单id, 查询详细
        :param request:
        :param args: queryId=11
        :param kwargs:
        :return:
        """
        try:
            query_id = json.loads(request.body)['params']['queryId']
            if query_id is not None and query_id != '':
                query_deploy_id = DeployTask.objects.filter(
                    pk=query_id).order_by('id')
                paginator = StandardResultsSetPagination()
                page_deploy_list = paginator.paginate_queryset(query_deploy_id,
                                                               self.request,
                                                               view=self)
                serializer_deploy_info = ApprovalListSerializer(
                    page_deploy_list, many=True)
                page_deploy = paginator.get_paginated_response(
                    serializer_deploy_info.data)
                return Response(page_deploy.data)

            logger.warning('部署单id不正确, 当前无法查看部署单详情')

        except BaseException as e:
            logger.error('用户:%s 请求部署单详情接口出现系统异常, 原因: %s' % request.user.name,
                         str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": e
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #6
0
    def get(self, request, *args, **kwargs):
        """
        工单类型
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            obj_data = TicketType.objects.all()
            paginator = StandardResultsSetPagination()
            page_ticket_type_list = paginator.paginate_queryset(obj_data,
                                                                self.request,
                                                                view=self)
            serializer_ticket_type_info = TicketTypeModelSerializers(
                page_ticket_type_list, many=True)
            page_ticket = paginator.get_paginated_response(
                serializer_ticket_type_info.data)
            return Response(page_ticket.data)

        except BaseException:
            logger.error("请求工单类型出错: %s" % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #7
0
    def post(self, request, *args, **kwargs):
        """
        根据项目名称查询
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            keywords = json.loads(request.body)['params']
            query_project = Project.objects.filter(
                title__icontains=keywords).order_by('id')
            paginator = StandardResultsSetPagination()
            project_list = paginator.paginate_queryset(query_project,
                                                       self.request,
                                                       view=self)
            serializer_project_info = ProjectModelSerializers(project_list,
                                                              many=True)
            project_page = paginator.get_paginated_response(
                serializer_project_info.data)
            return Response(project_page.data)

        except BaseException as e:
            logger.error("系统异常, 原因: %s" % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": e
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #8
0
    def get(self, request, *args, **kwargs):
        """
        /api/v1/gray/list
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:

            query_project = GrayType.objects.all()
            paginator = StandardResultsSetPagination()
            gray_list = paginator.paginate_queryset(query_project,
                                                    self.request,
                                                    view=self)
            serializer_gray_info = GrayModelSerializers(gray_list, many=True)
            gray_page = paginator.get_paginated_response(
                serializer_gray_info.data)
            return Response(gray_page.data)

        except BaseException as e:
            logger.error('系统异常, 异常原因: %s' % str(traceback.format_exc()), e)
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #9
0
    def get(self, request, *args, **kwargs):
        ticket_id = request.GET.get('ticketId', None)

        if ticket_id is None:
            return JsonResponse(data={'errcode': 404, 'msg': '获取工单错误!'})
        try:
            if request.user.is_superuser:
                obj_ticket_list = Ticket.objects.filter(
                    ticket_number=ticket_id)
                paginator = StandardResultsSetPagination()
                page_ticket_list = paginator.paginate_queryset(obj_ticket_list,
                                                               self.request,
                                                               view=self)
                serializer_ticket_info = TicketRecordrListModelSerializers(
                    page_ticket_list, many=True)
                page_ticket_record = paginator.get_paginated_response(
                    serializer_ticket_info.data)
                return Response(page_ticket_record.data)

            else:
                obj_ticket_list = Ticket.objects.filter(
                    ticket_number=ticket_id)
                account = Ticket.objects.get(ticket_number=ticket_id)
                if int(request.user.user_id) != int(account.submit_account_id):
                    return JsonResponse(data={
                        'errcode': 404,
                        'msg': '获取工单错误!'
                    })
                paginator = StandardResultsSetPagination()
                page_ticket_list = paginator.paginate_queryset(obj_ticket_list,
                                                               self.request,
                                                               view=self)
                serializer_ticket_info = TicketRecordrListModelSerializers(
                    page_ticket_list, many=True)
                page_ticket_record = paginator.get_paginated_response(
                    serializer_ticket_info.data)
                return Response(page_ticket_record.data)

        except BaseException:
            logger.error("查看工单详情出错: %s" % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #10
0
 def get(self, request):
     # 获取所有测试用例
     queryset = TestCase.objects.all().order_by('-id')
     paginator = StandardResultsSetPagination()
     case_list = paginator.paginate_queryset(queryset,
                                             self.request,
                                             view=self)
     serializer_case_info = TestCaseSerializerAll(case_list, many=True)
     case_page = paginator.get_paginated_response(serializer_case_info.data)
     return Response(case_page.data)
Пример #11
0
    def get(self, request, *args, **kwargs):
        """
        获取工单
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            if request.user.is_superuser:
                obj_ticket_list = Ticket.objects.all()
                paginator = StandardResultsSetPagination()
                page_ticket_list = paginator.paginate_queryset(obj_ticket_list,
                                                               self.request,
                                                               view=self)
                serializer_ticket_info = TicketRecordrListModelSerializers(
                    page_ticket_list, many=True)
                page_ticket_record = paginator.get_paginated_response(
                    serializer_ticket_info.data)
                return Response(page_ticket_record.data)
            else:
                obj_ticket_list = Ticket.objects.filter(
                    submit_account=request.user.user_id)
                paginator = StandardResultsSetPagination()
                page_ticket_list = paginator.paginate_queryset(obj_ticket_list,
                                                               self.request,
                                                               view=self)
                serializer_ticket_info = TicketRecordrListModelSerializers(
                    page_ticket_list, many=True)
                page_ticket_record = paginator.get_paginated_response(
                    serializer_ticket_info.data)
                return Response(page_ticket_record.data)

        except BaseException as e:
            logger.error("系统异常: %s" % str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})
Пример #12
0
 def get(self, request):
     # 获取所有测试用例任务
     case_id = request.query_params['caseId']
     queryset = TestTask.objects.filter(case_id=case_id).order_by('-id')
     paginator = StandardResultsSetPagination()
     case_list = paginator.paginate_queryset(queryset,
                                             self.request,
                                             view=self)
     serializer_case_info = TestCaseTaskSerializerOther(case_list,
                                                        many=True)
     case_page = paginator.get_paginated_response(serializer_case_info.data)
     return Response(case_page.data)
Пример #13
0
 def get(self, request, *args, **kwargs):
     """
     灰度规则
     :param request:
     :param args:
     :param kwargs:
     :return:
     """
     query_gray_domain = GrayDomain.objects.all()
     paginator = StandardResultsSetPagination()
     gray_domain_list = paginator.paginate_queryset(query_gray_domain, self.request, view=self)
     serializer_gray_info = GrayDomainModelSerializers(gray_domain_list, many=True)
     gray_domain_page = paginator.get_paginated_response(serializer_gray_info.data)
     return Response(gray_domain_page.data)
Пример #14
0
 def get(self, request, *args, **kwargs):
     """
     用户账号
     :param request:
     :param args:
     :param kwargs:
     :return:
     """
     obj_data = AccountType.objects.all()
     paginator = StandardResultsSetPagination()
     page_account_list = paginator.paginate_queryset(obj_data, self.request, view=self)
     serializer_account_info = AccountModelSerializers(page_account_list, many=True)
     page_account = paginator.get_paginated_response(serializer_account_info.data)
     return Response(page_account.data)
Пример #15
0
    def get(self, request, *args, **kwargs):
        """
        发布单审批列表
        :param request:
        :param args:
        :param kwargs:
        :return:
        """

        try:
            _status = request.GET.get('status', None)
            keywords = request.GET.get('keywords', None)
            if _status is not None:
                if _status == 'large':
                    query_deploy = DeployTask.objects.all().order_by('-id')
                    paginator = StandardResultsSetPagination()
                    deploy_list = paginator.paginate_queryset(query_deploy,
                                                              self.request,
                                                              view=self)
                    serializer_deploy_info = ApprovalListSerializer(
                        deploy_list, many=True)
                    deploy_page = paginator.get_paginated_response(
                        serializer_deploy_info.data)
                    return Response(deploy_page.data)

                else:
                    query_deploy = DeployTask.objects.filter(
                        status=_status).order_by('-id')
                    paginator = StandardResultsSetPagination()
                    deploy_list = paginator.paginate_queryset(query_deploy,
                                                              self.request,
                                                              view=self)
                    serializer_deploy_info = ApprovalListSerializer(
                        deploy_list, many=True)
                    deploy_page = paginator.get_paginated_response(
                        serializer_deploy_info.data)
                    return Response(deploy_page.data)

            elif keywords is not None:
                query_deploy = DeployTask.objects.filter(
                    Q(version__icontains=keywords)).order_by('-id')
                paginator = StandardResultsSetPagination()
                deploy_list = paginator.paginate_queryset(query_deploy,
                                                          self.request,
                                                          view=self)
                serializer_deploy_info = ApprovalListSerializer(deploy_list,
                                                                many=True)
                deploy_page = paginator.get_paginated_response(
                    serializer_deploy_info.data)
                return Response(deploy_page.data)

            else:
                query_deploy = DeployTask.objects.all().order_by('-id')
                paginator = StandardResultsSetPagination()
                deploy_list = paginator.paginate_queryset(query_deploy,
                                                          self.request,
                                                          view=self)
                serializer_deploy_info = ApprovalListSerializer(deploy_list,
                                                                many=True)
                deploy_page = paginator.get_paginated_response(
                    serializer_deploy_info.data)
                return Response(deploy_page.data)

        except BaseException as e:
            logger.error('%s 请求获取审批列表接口失败, 异常原因:%s' %
                         (request.user.name, str(e)))
            logger.error('请求获取审批列表接口失败, 异常原因: %s' %
                         str(traceback.format_exc()))
            return JsonResponse(data={
                "errcode": "1006",
                "msg": "系统异常, 请刷新重试!",
                "data": "null"
            },
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                json_dumps_params={'ensure_ascii': False})