Пример #1
0
    def get_context_data(self, **kwargs):
        context = super(AllTicket, self).get_context_data(**kwargs)
        request_data = self.request.GET
        #filter ticket in the future if necessary
        sn = request_data.get('sn', '')
        title = request_data.get('title', '')
        username = request_data.get('username', '')
        create_start = request_data.get('create_start', '')
        create_end = request_data.get('create_end', '')
        workflow_ids = request_data.get('workflow_ids', '')
        reverse = int(request_data.get('reverse', 1))
        per_page = int(request_data.get('per_page', 10))
        page = int(request_data.get('page', 1))
        # 待办,关联的,创建
        category = request_data.get('category')

        ins = WorkFlowAPiRequest(appname='ops',
                                 username=self.request.user.username)
        status, state_result = ins.getdata(parameters=dict(
            username=self.request.user.username, category='all'),
                                           method='get',
                                           url='/api/v1.0/tickets')
        if status:
            if len(state_result) > 0 and isinstance(
                    state_result, dict) and 'data' in state_result.keys(
                    ) and 'value' in state_result['data'].keys():
                context['ticket_result_restful_list'] = state_result['data'][
                    'value']
        context['msg'] = state_result['msg']
        return context
Пример #2
0
 def patch(self, request, *args, **kwargs):
     json_str = request.body.decode('utf-8')
     request_data_dict = json.loads(json_str)
     ins = WorkFlowAPiRequest(appname='ops',
                              username=self.request.user.username)
     status, state_result = ins.getdata(
         parameters=dict(username=self.request.user.username),
         data=request_data_dict,
         method='patch',
         url='/api/v1.0/tickets/{0}'.format(self.kwargs.get('ticket_id')))
     #handle message bug
     return JsonResponse(state_result)
Пример #3
0
 def get(self, request, *args, **kwargs):
     request_data = request.GET
     ticket_id = kwargs.get('ticket_id')
     username = request_data.get('username',
                                 request.user.username)  # 可用于权限控制
     ins = WorkFlowAPiRequest(username=self.request.user.username)
     status, state_result = ins.getdata(
         parameters={},
         method='get',
         url='/api/v1.0/tickets/{0}/flowsteps'.format(
             self.kwargs.get('ticket_id')))
     return JsonResponse(data=state_result)
Пример #4
0
    def form_valid(self, form):
        # save ticket
        if 'transition_id' in form.data.keys():
            transition_id = form.data['transition_id']
            form_data = form.cleaned_data
            form_data['transition_id'] = int(transition_id)
            # suggestion
            ticket_id = int(self.kwargs.get('ticket_id'))
            file_keys = list(form.files.keys())
            suggestion = form.data['suggestion']
            form_data['suggestion'] = suggestion
            title = form.data["title"]

            for file_key in file_keys:
                # 存放
                file = form.files[file_key].file
                file_name = form.files[file_key].name
                curr_time = datetime.datetime.now()
                # form_data[file_key] = os.path.abspath(os.curdir) + '/media/' + title + '/' + str(int(time.time())) + file_name
                form_data[file_key] = os.path.abspath(os.curdir) + '/media/' + title +"/"  + str(curr_time.date()) + '_' + str(curr_time.hour)+ \
                                      '-' + str(curr_time.minute) + '-' + str(curr_time.second) + '-' + str(curr_time.microsecond) + '_' + file_name
                Util.saveFile(file, form_data[file_key])

            for key, value in form_data.items():
                # 原始代码:if isinstance(value, datetime.datetime):
                # 修改后解决了日期、日期时间的问题
                if isinstance(value, datetime.date):
                    form_data[key] = form.data[key]

            ins = WorkFlowAPiRequest(username=self.request.user.username)
            status, state_result = ins.getdata(
                data=form_data,
                method='patch',
                url='/api/v1.0/tickets/{0}'.format(ticket_id))

            if 'b_guanliyuanshenpi_char_xiangmubianhao' in form_data.keys(
            ) and form_data['b_guanliyuanshenpi_char_xiangmubianhao'] != None:
                try:
                    tempFlowIdRelation = TempFlowIdRelation.objects.get(
                        ticket_id=ticket_id)
                    tempFlowIdRelation.ticket_id = state_result["ticket_id"]
                    tempFlowIdRelation.project_id = form_data[
                        'b_guanliyuanshenpi_char_xiangmubianhao']
                    tempFlowIdRelation.save()
                except:
                    tempFlowIdRelation = TempFlowIdRelation()
                    tempFlowIdRelation.ticket_id = ticket_id
                    tempFlowIdRelation.project_id = form_data[
                        'b_guanliyuanshenpi_char_xiangmubianhao']
                    tempFlowIdRelation.save()

        return super().form_valid(form)
Пример #5
0
 def get_context_data(self, **kwargs):
     context = super(Index, self).get_context_data(**kwargs)
     #context['workflows'] = Workflow.objects.all()
     ins = WorkFlowAPiRequest(appname='ops',
                              username=self.request.user.username)
     status, data = ins.getdata(dict(username=self.request.user.username,
                                     per_page=20,
                                     name=''),
                                method='get',
                                url='/api/v1.0/workflows')
     if status:
         context['workflows'] = data['data']['value']
     return context
Пример #6
0
 def get(self, request, *args, **kwargs):
     request_data = request.GET
     ticket_id = kwargs.get('ticket_id')
     username = request_data.get('username', '')
     if not username:
         return api_response(-1, '参数不全,请提供username', '')
     ins = WorkFlowAPiRequest(appname='ops',
                              username=self.request.user.username)
     status, state_result = ins.getdata(
         parameters=dict(username=self.request.user.username),
         method='get',
         url='/api/v1.0/tickets/{0}/transitions'.format(
             self.kwargs.get('ticket_id')))
     return JsonResponse(data=state_result)
Пример #7
0
    def get_context_data(self, **kwargs):
        context = super(NewPro, self).get_context_data(**kwargs)
        user_name = self.request.user.username
        #context['workflows'] = Workflow.objects.all()
        ins = WorkFlowAPiRequest(username=user_name)
        status, data = ins.getdata(dict(per_page=20, name=''),
                                   method='get',
                                   url='/api/v1.0/workflows')
        #print(data['value'])
        if status:
            context['workflows'] = data['data']['value']

        Util.judgePremission(user_name, context)

        return context
Пример #8
0
    def get(self, request, *args, **kwargs):
        request_data = request.GET
        ticket_id = kwargs.get('ticket_id')
        username = request_data.get('username',
                                    request.user.username)  # 可用于权限控制
        per_page = int(request_data.get('per_page', 10))
        page = int(request_data.get('page', 1))

        ins = WorkFlowAPiRequest(appname='ops',
                                 username=self.request.user.username)
        status, state_result = ins.getdata(
            parameters=dict(username=self.request.user.username),
            method='get',
            url='/api/v1.0/tickets/{0}/flowlogs'.format(
                self.kwargs.get('ticket_id')))
        return JsonResponse(data=state_result)
Пример #9
0
    def get_context_data(self, **kwargs):
        context = super(AllTicket, self).get_context_data(**kwargs)
        request_data = self.request.GET
        #filter ticket in the future if necessary
        sn = request_data.get('sn', '')
        title = request_data.get('title', '')
        username = request_data.get('username', '')
        create_start = request_data.get('create_start', '')
        create_end = request_data.get('create_end', '')
        workflow_ids = request_data.get('workflow_ids', '')
        reverse = int(request_data.get('reverse', 1))
        per_page = int(request_data.get('per_page', 10))
        page = int(request_data.get('page', 1))
        # 待办,关联的,创建
        category = request_data.get('category')

        ins = WorkFlowAPiRequest(username=self.request.user.username)
        status, state_result = ins.getdata(parameters=dict(category='all',
                                                           per_page=10000000,
                                                           page=page),
                                           method='get',
                                           url='/api/v1.0/tickets')
        if status:
            if len(state_result) > 0 and isinstance(
                    state_result, dict) and 'data' in state_result.keys(
                    ) and 'value' in state_result['data'].keys():
                resultList = state_result['data']['value']
                for item in resultList:
                    if item['state']['state_name'] == '施工进度':
                        item['showFlowChatFlag'] = True
                    else:
                        item['showFlowChatFlag'] = False
                    try:
                        flowretion = TempFlowIdRelation.objects.get(
                            ticket_id=item['id'])
                        item['project_id'] = flowretion.project_id
                    except:
                        item['project_id'] = "等待指定"

                context['ticket_result_restful_list'] = resultList
        context['msg'] = state_result['msg']

        try:
            Util.judgePremission(self.request.user.username, context)
        except:
            pass
        return context
Пример #10
0
 def get(self, request, *args, **kwargs):
     request_data = request.GET
     ticket_id = kwargs.get('ticket_id')
     username = request_data.get('username',
                                 request.user.username)  # 可用于权限控制
     suggestion = request_data.get('suggestion')
     transitionid = request_data.get('transitionid')
     #
     form_data = dict()
     form_data['suggestion'] = suggestion
     form_data['transition_id'] = int(transitionid)
     ins = WorkFlowAPiRequest(username=self.request.user.username)
     status, state_result = ins.getdata(
         data=form_data,
         method='patch',
         url='/api/v1.0/tickets/{0}'.format(ticket_id))
     return JsonResponse(data=state_result)
Пример #11
0
    def get_context_data(self, **kwargs):
        context = super(MyToDoTicket, self).get_context_data(**kwargs)
        request_data = self.request.GET
        sn = request_data.get('sn', '')
        title = request_data.get('title', '')
        username = request_data.get('username', '')
        create_start = request_data.get('create_start', '')
        create_end = request_data.get('create_end', '')
        workflow_ids = request_data.get('workflow_ids', '')
        reverse = int(request_data.get('reverse', 1))
        per_page = int(request_data.get('per_page', 10))
        page = int(request_data.get('page', 1))
        # 待办,关联的,创建
        category = request_data.get('category')
        #因为需要对应不同username,所以接口返回的数据也不同
        ins = WorkFlowAPiRequest(username=self.request.user.username)
        status, state_result = ins.getdata(parameters=dict(category='duty',
                                                           per_page=10000000,
                                                           page=page),
                                           method='get',
                                           url='/api/v1.0/tickets')
        #print(state_result)
        resultList = state_result['data']['value']
        for item in resultList:
            try:
                flowretion = TempFlowIdRelation.objects.get(
                    ticket_id=item['id'])
                item['project_id'] = flowretion.project_id
            except:
                item['project_id'] = "等待指定"

        if status:
            if len(state_result) > 0 and isinstance(
                    state_result,
                    dict) and 'data' in state_result.keys() and isinstance(
                        state_result['data'],
                        dict) and 'value' in state_result['data'].keys():
                context['ticket_result_restful_list'] = state_result['data'][
                    'value']
        context['msg'] = state_result['msg']
        #print(context)
        try:
            Util.judgePremission(self.request.user.username, context)
        except:
            pass
        return context
Пример #12
0
    def get_form_class(self):
        form_fields = dict()
        workflow_id = self.kwargs.get('workflow_id')

        # get ticket initial data
        ins = WorkFlowAPiRequest(username=self.request.user.username)
        status, state_result = ins.getdata(
            {},
            method='get',
            url='/api/v1.0/workflows/{0}/init_state'.format(workflow_id))
        state_result = state_result['data']
        self.kwargs.update({'state_result': state_result})

        #print(state_result.keys())
        if isinstance(state_result,
                      dict) and 'field_list' in state_result.keys():

            class DynamicForm(forms.Form):
                def __init__(self, *args, **kwargs):
                    self.helper = FormHelper()
                    self.helper.form_class = 'form-horizontal'
                    self.helper.label_class = 'col-md-2'
                    self.helper.field_class = 'col-md-8'
                    # DictionaryField bug
                    self.helper.layout = Layout(*[
                        Div(field['field_key'], css_class='form-group')
                        for field in state_result['field_list']
                    ])
                    super(DynamicForm, self).__init__(*args, **kwargs)

            for field in state_result['field_list']:
                if field['field_key'] == 'title':
                    field['field_name'] = "项目名称"
                    field['description'] = None
                Util.createWebDirex(field, forms, form_fields, User)
                # handle read only field
                if field['field_attribute'] == 1:
                    form_fields[field['field_key']].widget.attrs[
                        'disabled'] = 'disabled'
        else:
            raise Http404()
            # print(form_fields)

        return type('DynamicItemsForm', (DynamicForm, ), form_fields)
Пример #13
0
    def get(self, request, *args, **kwargs):
        """
        获取工作流列表
        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        request_data = request.GET
        name = request_data.get('name', '')
        per_page = int(request_data.get('per_page', 10))
        page = int(request_data.get('page', 1))
        username = request_data.get('username', '')  # 后续会根据username做必要的权限控制

        ins = WorkFlowAPiRequest(appname='ops',
                                 username=self.request.user.username)
        status, state_result = ins.getdata(
            parameters=dict(username=self.request.user.username),
            method='get',
            url='/api/v1.0/tickets/{0}'.format(self.kwargs.get('ticket_id')))
        return JsonResponse(data=state_result)
Пример #14
0
    def form_valid(self, form):
        # save ticket
        if 'transition_id' in form.data.keys():
            transition_id = form.data['transition_id']
            form_data = form.cleaned_data
            form_data['transition_id'] = int(transition_id)
            form_data['username'] = self.request.user.username
            form_data['workflow_id'] = int(self.kwargs.get('workflow_id'))
            for key, value in form_data.items():
                if isinstance(value, datetime.datetime):
                    form_data[key] = form.data[key]

            #for test only
            ins = WorkFlowAPiRequest(appname='ops',
                                     username=self.request.user.username)
            status, state_result = ins.getdata(data=form_data,
                                               method='post',
                                               url='/api/v1.0/tickets')
            # if new_ticket_result:
            # code, data = 0, {'ticket_id': new_ticket_result}
            # else:
            # code, data = -1, {}
        return super().form_valid(form)
Пример #15
0
    def form_valid(self, form):
        # save ticket
        if 'transition_id' in form.data.keys():

            transition_id = form.data['transition_id']
            form_data = form.cleaned_data
            form_data['transition_id'] = int(transition_id)
            # form_data['username'] = self.request.user.username
            form_data['workflow_id'] = int(self.kwargs.get('workflow_id'))
            file_keys = list(form.files.keys())
            title = form.data["title"]
            for file_key in file_keys:
                #存放
                file = form.files[file_key].file
                file_name = form.files[file_key].name
                curr_time = datetime.datetime.now()
                form_data[file_key] = os.path.abspath(os.curdir)+ '/media/' + title +"/"  + str(curr_time.date()) + '_' + str(curr_time.hour)+ \
                                      '-' + str(curr_time.minute) + '-' + str(curr_time.second) + '-' + str(curr_time.microsecond) + '_' + file_name
                Util.saveFile(file, form_data[file_key])

            for key, value in form_data.items():
                #原始代码:if isinstance(value, datetime.datetime):
                # 修改后解决了日期、日期时间的问题
                if isinstance(value, datetime.date):
                    form_data[key] = form.data[key]

            # for test only
            ins = WorkFlowAPiRequest(username=self.request.user.username)
            status, state_result = ins.getdata(data=form_data,
                                               method='post',
                                               url='/api/v1.0/tickets')
            # if new_ticket_result:
            # code, data = 0, {'ticket_id': new_ticket_result}
            # else:
            # code, data = -1, {}
        return super().form_valid(form)
Пример #16
0
 def get(self, request):
     ins = WorkFlowAPiRequest(username="******")
     status, state_result = ins.getdata(
         method='get', url='/api/v1.0/tickets/num_statistics')
     # print(state_result)
     return Response({'code': 0, 'msg': 'ok', 'data': state_result['data']})
Пример #17
0
    def get_form_class(self):
        form_fields = dict()
        workflow_id = self.kwargs.get('workflow_id')

        #get ticket initial data
        ins = WorkFlowAPiRequest(appname='ops',
                                 username=self.request.user.username)
        status, state_result = ins.getdata(
            dict(username=self.request.user.username),
            method='get',
            url='/api/v1.0/workflows/{0}/init_state'.format(workflow_id))
        """
        state_result example
            {
              'data': {
                'id': 6,
                'name': '发起人-新建中',
                'creator': 'admin',
                'gmt_created': '2018-05-10 07:34:45',
                'distribute_type_id': 1,
                'transition': [
                  {
                    'transition_name': '提交',
                    'transition_id': 7
                  }
                ],
                'order_id': 1,
                'participant_type_id': 5,
                'type_id': 1,
                'is_hidden': False,
                'field_list': [
                  {
                    'boolean_field_display': {
                      
                    },
                    'order_id': 20,
                    'default_value': None,
                    'field_name': '标题',
                    'field_choice': {
                      
                    },
                    'field_key': 'title',
                    'field_type_id': 5,
                    'field_value': None,
                    'field_attribute': 2,
                    'field_template': '',
                    'description': '工单的标题'
                  },
                  {
                    'boolean_field_display': {
                      
                    },
                    'order_id': 110,
                    'default_value': '请填写申请vpn的理由',
                    'field_name': '申请原因',
                    'field_choice': {
                      
                    },
                    'field_key': 'vpn_reason',
                    'field_type_id': 55,
                    'field_value': None,
                    'field_attribute': 2,
                    'field_template': '',
                    'description': 'vpn申请原因'
                  }
                ],
                'participant': 'creator',
                'sub_workflow_id': 0,
                'workflow_id': 2,
                'label': {
                  
                }
              },
              'msg': '',
              'code': 0
            }
        """
        state_result = state_result['data']
        #set state_result to kwargs to avoid mutiple time to obtain ticket info
        self.kwargs.update({'state_result': state_result})

        if isinstance(state_result,
                      dict) and 'field_list' in state_result.keys():

            class DynamicForm(forms.Form):
                def __init__(self, *args, **kwargs):
                    self.helper = FormHelper()
                    self.helper.form_class = 'form-horizontal'
                    self.helper.label_class = 'col-md-2'
                    self.helper.field_class = 'col-md-8'
                    # DictionaryField bug
                    self.helper.layout = Layout(*[
                        Div(field['field_key'], css_class='form-group')
                        for field in state_result['field_list']
                    ])
                    super(DynamicForm, self).__init__(*args, **kwargs)

            for field in state_result['field_list']:
                FIELD_TYPE_STR = 5  # 字符串类型
                FIELD_TYPE_INT = 10  # 整形类型
                FIELD_TYPE_FLOAT = 15  # 浮点类型
                FIELD_TYPE_BOOL = 20  # 布尔类型
                FIELD_TYPE_DATE = 25  # 日期类型
                FIELD_TYPE_DATETIME = 30  # 日期时间类型
                FIELD_TYPE_RADIO = 35  # 单选框
                FIELD_TYPE_CHECKBOX = 40  # 多选框
                FIELD_TYPE_SELECT = 45  # 下拉列表
                FIELD_TYPE_MULTI_SELECT = 50  # 多选下拉列表
                FIELD_TYPE_TEXT = 55  # 文本域
                FIELD_TYPE_USERNAME = 60  # 用户名,前端展现时需要调用方系统获取用户列表。loonflow只保存用户名
                if field['field_type_id'] == 5:
                    form_fields[field['field_key']] = forms.CharField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        widget=forms.TextInput(
                            attrs={'placeholder': field['field_name']}))
                elif field['field_type_id'] in [10, 15]:
                    form_fields[field['field_key']] = forms.IntegerField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        widget=forms.NumberInput(
                            attrs={'placeholder': field['field_name']}))
                elif field['field_type_id'] == 20:
                    form_fields[field['field_key']] = forms.BooleanField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']})
                elif field['field_type_id'] == 25:
                    form_fields[field['field_key']] = forms.DateField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        widget=forms.DateInput(
                            attrs={
                                'placeholder': field['field_name'],
                                'class': 'dateinput'
                            }))
                elif field['field_type_id'] == 30:
                    form_fields[field['field_key']] = forms.DateTimeField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        widget=forms.DateTimeInput(
                            attrs={
                                'placeholder': field['field_name'],
                                'class': 'datetimeinput'
                            }))
                elif field['field_type_id'] in [35, 45]:
                    form_fields[field['field_key']] = forms.ChoiceField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        choices=[(k, v)
                                 for k, v in field['field_choice'].items()])
                elif field['field_type_id'] == [40, 50]:
                    form_fields[
                        field['field_key']] = forms.MultipleChoiceField(
                            help_text=field['description'],
                            label=field['field_name'],
                            required=True
                            if field['field_attribute'] == 2 else False,
                            initial=field['default_value'],
                            error_messages={'required': field['description']},
                            choices=[(k, v)
                                     for k, v in field['field_choice'].items()
                                     ])
                elif field['field_type_id'] == 55:
                    form_fields[field['field_key']] = forms.CharField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        widget=CKEditorUploadingWidget(
                            attrs={
                                'placeholder': field['field_name'],
                                'cols': 20,
                                'rows': 10
                            }))
                elif field['field_type_id'] == 60:
                    form_fields[field['field_key']] = forms.ChoiceField(
                        help_text=field['description'],
                        label=field['field_name'],
                        required=True
                        if field['field_attribute'] == 2 else False,
                        initial=field['default_value'],
                        error_messages={'required': field['description']},
                        choices=[(i.username, i.username)
                                 for i in User.objects.all()])
                # handle read only field
                if field['field_attribute'] == 1:
                    form_fields[field['field_key']].widget.attrs[
                        'disabled'] = 'disabled'
        else:
            raise Http404()
        return type('DynamicItemsForm', (DynamicForm, ), form_fields)
Пример #18
0
    def get_form_class(self):
        form_fields = dict()
        ticket_id = self.kwargs.get('ticket_id')

        ins = WorkFlowAPiRequest(username=self.request.user.username)

        #调用接口获取控件
        status, state_result = ins.getdata(
            parameters={},
            method='get',
            url='/api/v1.0/tickets/{0}'.format(ticket_id))
        #获取提交按钮
        status2, state_result2 = ins.getdata(
            parameters={},
            method='get',
            url='/api/v1.0/tickets/{0}/transitions'.format(
                self.kwargs.get('ticket_id')))

        state_result = state_result['data']['value']
        state_result2 = state_result2['data']['value']

        out_list = list()

        if isinstance(state_result,
                      dict) and 'field_list' in state_result.keys():

            class DynamicForm(forms.Form):
                def __init__(self, *args, **kwargs):
                    self.helper = FormHelper()
                    self.helper.form_class = 'form-horizontal'
                    self.helper.form_action = " "
                    self.helper.label_class = 'col-md-label'
                    self.helper.field_class = 'col-md-field'
                    # DictionaryField bug
                    self.helper.layout = Layout(*[
                        Div(field['field_key'], css_class='form-table-group')
                        for field in state_result['field_list']
                    ])
                    super(DynamicForm, self).__init__(*args, **kwargs)

            find_is_null = False
            j_shigongjindu_float_zonghengzumaosuo = ""
            j_shigongjindu_float_zongqiefengzhuankong = ""
            j_shigongjindu_float_zongbaopoliefeng = ""
            j_shigongjindu_float_muqianhengzumaosuo = ""
            j_shigongjindu_float_muqianqiefengzhuankong = ""
            j_shigongjindu_float_muqianbaopoliefeng = ""
            try:
                temWork = TempWork.objects.get(ticket_id=ticket_id)

                recode = eval(temWork.process_recod)

                j_shigongjindu_float_zonghengzumaosuo = recode[
                    "j_shigongjindu_float_zonghengzumaosuo"]
                j_shigongjindu_float_zongqiefengzhuankong = recode[
                    "j_shigongjindu_float_zongqiefengzhuankong"]
                j_shigongjindu_float_zongbaopoliefeng = recode[
                    "j_shigongjindu_float_zongbaopoliefeng"]

                j_shigongjindu_float_muqianhengzumaosuo = recode[
                    "j_shigongjindu_float_muqianhengzumaosuo"]
                j_shigongjindu_float_muqianqiefengzhuankong = recode[
                    "j_shigongjindu_float_muqianqiefengzhuankong"]
                j_shigongjindu_float_muqianbaopoliefeng = recode[
                    "j_shigongjindu_float_muqianbaopoliefeng"]

                find_is_null = True
            except TempWork.DoesNotExist:
                pass

            for field in state_result['field_list']:

                attributeFlag = field["field_attribute"]
                # 1只读,2必填,3选填
                #创建时候,只有是必须填写或者选填的才进行渲染  'field_key' (140598713991728) 'b_guanliyuanshenpi_char_xiangmuliushuihao'
                if attributeFlag != 1:
                    if field[
                            'field_key'] == 'b_guanliyuanshenpi_char_xiangmuliushuihao':
                        field['field_attribute'] = 3

                    if field[
                            'field_key'] == 'j_shigongjindu_float_zonghengzumaosuo':
                        field[
                            'default_value'] = j_shigongjindu_float_zonghengzumaosuo

                    if field[
                            'field_key'] == 'j_shigongjindu_float_zongqiefengzhuankong':
                        field[
                            'default_value'] = j_shigongjindu_float_zongqiefengzhuankong

                    if field[
                            'field_key'] == 'j_shigongjindu_float_zongbaopoliefeng':
                        field[
                            'default_value'] = j_shigongjindu_float_zongbaopoliefeng

                    if field[
                            'field_key'] == 'j_shigongjindu_float_muqianhengzumaosuo':
                        field[
                            'default_value'] = j_shigongjindu_float_muqianhengzumaosuo

                    if field[
                            'field_key'] == 'j_shigongjindu_float_muqianqiefengzhuankong':
                        field[
                            'default_value'] = j_shigongjindu_float_muqianqiefengzhuankong

                    if field[
                            'field_key'] == 'j_shigongjindu_float_muqianbaopoliefeng':
                        field[
                            'default_value'] = j_shigongjindu_float_muqianbaopoliefeng

                    if field[
                            'field_key'] == 'b_guanliyuanshenpi_char_xiangmubianhao':
                        try:
                            flowretion = TempFlowIdRelation.objects.get(
                                ticket_id=self.kwargs.get('ticket_id'))
                            field['default_value'] = flowretion.project_id
                        except:
                            pass

                    out_list.append(field)

                    Util.createWebDirex(field, forms, form_fields, User)
                # handle read only field
                # if field['field_attribute'] == 1:
                #     form_fields[field['field_key']
                #     ].widget.attrs['disabled'] = 'disabled'
        else:
            raise Http404()

        state_result['field_list'] = out_list
        self.kwargs.update({'state_result': state_result})
        self.kwargs.update({'title': state_result["title"]})
        self.kwargs.update({'state_result2': state_result2})
        if (len(state_result['field_list']) != 0):
            self.kwargs.update({'showSuggestion': 'true'})
        return type('DynamicItemsForm', (DynamicForm, ), form_fields)
Пример #19
0
    def get(self, request):
        params = json.loads(dict(request.query_params)['dataArray'][0])
        per_page = int(params['pagesize'])
        page = int(params['page'])
        category = params['category']
        searchKey = params['searchKey']
        order = params['order']
        ins = WorkFlowAPiRequest(username=self.request.user.username)
        status, state_result = ins.getdata(parameters=dict(category=category,
                                                           per_page=per_page,
                                                           page=page,
                                                           title=searchKey),
                                           method='get',
                                           url='/api/v1.0/tickets')
        mytotal = 0
        status2, state_result2 = ins.getdata(parameters=dict(category=category,
                                                             per_page=10000000,
                                                             page=1,
                                                             title=searchKey),
                                             method='get',
                                             url='/api/v1.0/tickets')
        mytotal = len(state_result2['data']['value'])
        outlist = list()
        outlen = 0
        if status:
            if len(state_result) > 0 and isinstance(
                    state_result, dict) and 'data' in state_result.keys(
                    ) and 'value' in state_result['data'].keys():
                resultList = state_result['data']['value']
                for item in resultList:
                    flowid = item['workflow_info']['workflow_name'] + item['sn']
                    projectid = "等待指定"
                    try:
                        flowretion = TempFlowIdRelation.objects.get(
                            ticket_id=item['id'])
                        projectid = flowretion.project_id
                    except:
                        pass
                    title = item['title']
                    state_name = item['state']['state_name']
                    creator = item['creator']
                    gmt_created = item['gmt_created']
                    gmt_modified = item['gmt_modified']
                    id = item["id"]
                    workflow_name = item["workflow_info"]["workflow_name"]
                    a_href = "<a href='/workflow/ticket/{0}/?workflow_name={1}'>详情</a>".format(
                        id, workflow_name)
                    if item['state']['state_name'] == '施工进度':
                        a_href = a_href + (
                            "&nbsp;|&nbsp; <a href='/workflow/{}/tickeflowdetail'>进度</a> "
                            .format(id))
                    action = a_href

                    outdic = {
                        'flowid': flowid,
                        'projectid': projectid,
                        'title': title,
                        'state_name': state_name,
                        'creator': creator,
                        'gmt_created': gmt_created,
                        'gmt_modified': gmt_modified,
                        'action': action,
                    }
                    outlist.append(outdic)
        if order != "":
            sort_arr = str(order).split(",")
            if len(sort_arr) > 1:
                colum_str = str(sort_arr[0])

                if str(sort_arr[1]).upper() == "ASC":
                    outlist.sort(key=lambda x: (x.get(colum_str)),
                                 reverse=False)
                    outlen = len(outlist)
                else:
                    outlist.sort(key=lambda x: (x.get(colum_str)),
                                 reverse=True)
                    outlen = len(outlist)
        else:
            outlen = len(outlist)
        return Response({
            'code': 0,
            'msg': 'ok',
            'totalCount': outlen,
            'totalCounts': mytotal,
            'data': outlist,
        })
Пример #20
0
    def get_form_class(self):
        form_fields = dict()
        ticket_id = self.kwargs.get('ticket_id')

        ins = WorkFlowAPiRequest(username=self.request.user.username)

        # 获取组建
        status, state_result = ins.getdata(
            parameters={},
            method='get',
            url='/api/v1.0/tickets/{0}'.format(ticket_id))

        state_result = state_result['data']['value']

        out_list = list()
        file_out_list = list()

        if isinstance(state_result,
                      dict) and 'field_list' in state_result.keys():

            class DynamicForm(forms.Form):
                def __init__(self, *args, **kwargs):
                    self.helper = FormHelper()
                    self.helper.form_class = 'form-horizontal'
                    self.helper.form_action = " "
                    self.helper.label_class = 'col-md-label'
                    self.helper.field_class = 'col-md-field'
                    # DictionaryField bug
                    self.helper.layout = Layout(*[
                        Div(field['field_key'], css_class='form-table-group')
                        for field in state_result['field_list']
                    ])
                    super(DynamicForm, self).__init__(*args, **kwargs)

            for field in state_result['field_list']:
                if field['field_key'] == 'title':
                    field['field_name'] = "项目名称"
                    field['description'] = None
                if field[
                        'field_key'] == 'b_guanliyuanshenpi_char_xiangmuliushuihao':
                    field['field_value'] = self.request.session[
                        "workflow_name"] + state_result["sn"]
                attributeFlag = field["field_attribute"]
                # 将控件的值提读出来
                field["default_value"] = field["field_value"]
                # 1只读,2必填,3选填
                # 创建时候,只有是必须填写或者选填的才进行渲染
                if attributeFlag == 1:
                    if field['field_type_id'] == 80:
                        #控件是文件类型,画面中生成<a>标签就可以
                        item = dict()
                        path = field['field_value']
                        if path == None:
                            continue
                        else:
                            mypath = "."
                            index = 0
                            contineFlag = 0
                            for file_path_part in path.split("/"):
                                if (contineFlag == 1
                                        or file_path_part == "media"):
                                    mypath += "/" + file_path_part
                                    contineFlag = 1
                                else:
                                    index += 1
                                    continue
                            file_orgin = path.split("/")[len(path.split("/")) -
                                                         1]
                            file_name = file_orgin.split("_")[2]
                            item['field_name'] = field["field_name"]
                            item[
                                'download_path'] = "/workflow/" + ticket_id + "/download_file?path=" + mypath
                            item['link_name'] = file_name
                            file_out_list.append(item)
                            continue
                    out_list.append(field)
                    Util.createWebDirex(field, forms, form_fields, User)
                # handle read only field
                if field['field_attribute'] == 1:
                    form_fields[field['field_key']].widget.attrs[
                        'disabled'] = 'disabled'
        else:
            raise Http404()

        state_result['field_list'] = out_list
        self.kwargs.update({'state_result': state_result})
        #file_out_list
        self.kwargs.update({'file_out_list': file_out_list})
        self.kwargs.update({'title': state_result["title"]})

        return type('DynamicItemsForm', (DynamicForm, ), form_fields)