Ejemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        request_data = request.GET

        query_value = request_data.get('query_value', '')
        page = int(request_data.get('page', 1)) if request_data.get('page',
                                                                    0) else 1
        per_page = int(request_data.get('per_page', 10)) if request_data.get(
            'per_page', 10) else 10

        workflows, msg = WorkflowBaseService.get_workflows(
            query_value, per_page, page)

        if workflows is not False:
            workflow_serializer_list = [
                WorkflowSerializer(workflow) for workflow in workflows
            ]
            workflow_serializer_list = [
                workflow_serializer.data
                for workflow_serializer in workflow_serializer_list
            ]
            return format_response.JsonResponse(data=workflow_serializer_list,
                                                code=status.HTTP_200_OK,
                                                per_page=msg.get(
                                                    'per_page', ''),
                                                page=msg.get('page', ''),
                                                total=msg.get('total', ''))
        else:
            return format_response.JsonResponse(
                data='', code=status.HTTP_500_INTERNAL_SERVER_ERROR, msg=msg)
Ejemplo n.º 2
0
    def get(self, request):
        request_data = request.GET
        query_value = request_data.get('query_value', '')
        page = int(request_data.get('page', 1)) if request_data.get('page',
                                                                    0) else 1
        per_page = int(request_data.get('per_page', 10)) if request_data.get(
            'per_page', 10) else 10

        job_types, msg = JOB_TYPE_SERVICE.get_format_job_types(
            query_value, per_page, page)

        if job_types is not False:
            job_type_serializer_list = [
                FormatJobTypeSerializer(job_type) for job_type in job_types
            ]

            job_type_serializer_list = [
                JobTypeSerializer.data
                for JobTypeSerializer in job_type_serializer_list
            ]

            return format_response.JsonResponse(data=job_type_serializer_list,
                                                code=status.HTTP_200_OK,
                                                per_page=msg.get(
                                                    'per_page', ''),
                                                page=msg.get('page', ''),
                                                total=msg.get('total', ''))
        else:
            return format_response.JsonResponse(data='',
                                                code=status.HTTP_500_OK,
                                                msg=msg)
Ejemplo n.º 3
0
 def get(self, request, workflow_id, state_id):
     state, msg = WorkflowStateService.get_workflow_state_by_id(state_id)
     if state:
         result = WorkflowStateSerializer(state).data
         return format_response.JsonResponse(data=result,
                                             code=status.HTTP_200_OK)
     if state is None:
         return format_response.JsonResponse(data=[],
                                             code=status.HTTP_200_OK)
     if state is False:
         return format_response.JsonResponse(
             data='', code=status.HTTP_500_INTERNAL_SERVER_ERROR, msg=msg)
Ejemplo n.º 4
0
    def post(self, request):
        serializer = WorkflowSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return format_response.JsonResponse(data=serializer.data,
                                                code=status.HTTP_201_CREATED,
                                                msg='')
        else:

            return format_response.JsonResponse(
                data='',
                code=status.HTTP_400_BAD_REQUEST,
                msg=serializer._errors)
Ejemplo n.º 5
0
 def get(self, request, workflow_id):
     states, msg = WorkflowStateService.get_workflow_states(workflow_id)
     if states is not False:
         workflow_state_serializer_list = [
             WorkflowStateSerializer(state) for state in states
         ]
         workflow_state_serializer_list = [
             workflow_state_serializer.data
             for workflow_state_serializer in workflow_state_serializer_list
         ]
         return format_response.JsonResponse(
             data=workflow_state_serializer_list, code=status.HTTP_200_OK)
     else:
         return format_response.JsonResponse(
             data='', code=status.HTTP_500_INTERNAL_SERVER_ERROR, msg=msg)
Ejemplo n.º 6
0
 def get(self, request, pk):
     print(request.user.username)
     user = MyUser.objects.filter(is_deleted=False, id=pk)
     if user:
         data = MyUserSerializer(user.first())
         msg = ''
     else:
         data = {}
         msg = '不存在或已删除'
     return format_response.JsonResponse(data=data.data, code=status.HTTP_200_OK, msg=msg)
Ejemplo n.º 7
0
    def post(self, request):
        try:
            flowchart = request.FILES.get('flowchart', None)
            if not flowchart:
                return format_response.JsonResponse(
                    data='', code=status.HTTP_400_BAD_REQUEST, msg='请选择文件上传')
            import os
            file_name = flowchart.name
            real_name, ext = os.path.splitext(file_name)
            if ext not in ['.jpg', '.jpeg', '.png']:
                return format_response.JsonResponse(
                    data='',
                    code=status.HTTP_400_BAD_REQUEST,
                    msg='仅支持jpg,jpeg,png格式图片上传')

            import time

            new_file_path = os.path.join(settings.MEDIA_ROOT, 'flowchart')
            new_file_name = real_name + '_' + time.strftime(
                '%Y%m%d%H%M%S') + ext
            new_file_path_name = os.path.join(new_file_path, new_file_name)
            if not os.path.exists(new_file_path):
                os.makedirs(new_file_path)

            f = open(new_file_path_name, 'wb+')  # 打开特定的文件进行二进制的写操作
            for chunk in flowchart.chunks():  # 分块写入文件
                f.write(chunk)
            f.close()
            return format_response.JsonResponse(
                data={'file_name': new_file_name},
                code=status.HTTP_200_OK,
                msg='')
        except Exception as e:
            import logging
            import traceback
            logging.error(traceback.format_exc())
            return format_response.JsonResponse(
                data='',
                code=status.HTTP_500_INTERNAL_SERVER_ERROR,
                msg=e.__str__())
Ejemplo n.º 8
0
    def get(self, request):
        print(request.COOKIES)
        args = request.GET
        per_page = int(args.get('per_page', 10)) if args.get('per_page', 10) else 10
        page = int(args.get('page', 1)) if args.get('page', 1) else 1

        total = MyUser.objects.filter(is_deleted=False).count()

        user_serializer_list = [MyUserSerializer(user) for user in MyUser.objects.filter(is_deleted=False)]
        user_serializer_list = [user_serializer.data for user_serializer in user_serializer_list]

        return format_response.JsonResponse(data=user_serializer_list, code=status.HTTP_200_OK,
                                            msg='', per_page=per_page, page=page, total=total)
Ejemplo n.º 9
0
 def delete(self, request, workflow_id):
     result, msg = WorkflowBaseService.del_workflow_by_id(workflow_id)
     if result:
         return format_response.JsonResponse(data='',
                                             code=status.HTTP_200_OK,
                                             msg=msg)
Ejemplo n.º 10
0
 def get(self, request, workflow_id):
     workflow, msg = WorkflowBaseService.get_workflow_by_id(workflow_id)
     workflow_serializer = WorkflowSerializer(workflow).data
     return format_response.JsonResponse(data=workflow_serializer,
                                         code=status.HTTP_200_OK,
                                         msg=msg)