Beispiel #1
0
def getFormObjAjax(request):
    '''
    load service_object's form_object
    return: json
    author: Arthur
    '''
    username = request.user.username
    postdata = getPostdata(request)
    result = {}

    if username:
        require_field = ['api_path']
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            flow_uuid = FlowActiveGlobalObject.APIgetUUID(
                postdata.get('api_path'))
            thisQuery = list(
                FlowActive.objects.filter(flow_uuid=flow_uuid,
                                          undeploy_flag=False).values(
                                              'formobject', 'attachment'))
            if len(thisQuery):
                result = thisQuery[0]
                language = get_language()
                app_id = FlowActiveGlobalObject.UUIDSearch(
                    flow_uuid).flow_app_id
                formobject = Translator('formobject', 'active', language,
                                        app_id, None).Do(result['formobject'])
                result['formobject'] = json.dumps(formobject)
        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        error('%s get form_object with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Beispiel #2
0
 def threadsubmit(self):
     while True:
         #get pool queue size
         pool_qsize = self.threadPool._work_queue.qsize()
         #get queue size
         queue_size = self.threadQueue.qsize()
         if pool_qsize == 0 and queue_size > 0 and self.Monitor_Start:
             #get json form queue
             jsonObj = self.threadQueue.get(block=True)
             flow_uuid = jsonObj['param'].get('flow_uuid', '')
             fa = None
             if flow_uuid:
                 fa = FlowActiveGlobalObject.UUIDSearch(flow_uuid)
             #import module
             try:
                 module_name = jsonObj['module_name']
                 l = module_name.split('.')
                 if l[0] == 'omformflow' and fa and self.name == 'FormFlow':
                     if l[-2] != fa.version:
                         module_name = 'omformflow.production.' + flow_uuid + '.' + str(
                             fa.version) + '.main'
                 module = import_module(module_name)
                 #submit threads
                 self.threadPool.submit(getattr(module, jsonObj['method']),
                                        jsonObj['param'])
             except Exception as e:
                 try:
                     if fa:
                         error(_('找不到main.py') + str(e))
                     else:
                         error(_('找不到流程') + str(e))
                 except:
                     pass
         sleep(0.00001)
Beispiel #3
0
def getFormobjectListText(item_id, value, flow_uuid, formobject):
    item_id = item_id.upper()
    text = value
    lists = []
    if flow_uuid:
        fa = FlowActiveGlobalObject.UUIDSearch(flow_uuid)
        items = json.loads(fa.merge_formobject)
    else:
        if isinstance(formobject, str):
            formobject = json.loads(formobject)
        items = formobject['items']

    if isinstance(items, dict):
        item = items.get(item_id, {})
        lists = item.get('config', {}).get('lists', [])
    else:
        for item in items:
            if item['id'] == item_id:
                lists = item.get('config', {}).get('lists', [])
                break

    for l in lists:
        if l['value'] == value:
            text = l['text']
            break
    return text
Beispiel #4
0
 def datatable_multi_app(self, content):
     if isinstance(content, dict):
         for key in content:
             line = content[key]
             for s_k in line:
                 if isinstance(line[s_k], str):
                     if line.get('flow_uuid', None):
                         fa = FlowActiveGlobalObject.UUIDSearch(
                             line.get('flow_uuid', None))
                         if fa:
                             app_id = fa.flow_app_id
                         else:
                             app_id = None
                         app_name = None
                     else:
                         app_id = line.get('id', None)
                         app_name = line.get('app_name', None)
                     lan = FlowActiveGlobalObject.getAppLanDict(
                         self.trans_type, app_id,
                         app_name).get(self.language, {})
                     line[s_k] = self.fun(lan.get(line[s_k], line[s_k]),
                                          line[s_k])
     elif isinstance(content, list):
         for line in content:
             for s_k in line:
                 if isinstance(line[s_k], str):
                     if line.get('flow_uuid', None):
                         fa = FlowActiveGlobalObject.UUIDSearch(
                             line.get('flow_uuid', None))
                         if fa:
                             app_id = fa.flow_app_id
                         else:
                             app_id = None
                         app_name = None
                     else:
                         app_id = line.get('id', None)
                         app_name = line.get('app_name', None)
                     lan = FlowActiveGlobalObject.getAppLanDict(
                         self.trans_type, app_id,
                         app_name).get(self.language, {})
                     line[s_k] = self.fun(lan.get(line[s_k], line[s_k]),
                                          line[s_k])
     return content
Beispiel #5
0
def myformpage(request, url):
    '''
    system config page
    input:request
    return: system.html
    author:Jia Liu
    '''
    url_list = url.split('/')
    flow_uuid = url_list[0]
    data_no = url_list[1]
    try:
        fa = FlowActiveGlobalObject.UUIDSearch(flow_uuid)
        if fa:
            app_id = fa.flow_app_id
        if len(url_list) == 2:
            model = getModel('omformmodel', 'Omdata_' + flow_uuid)
            omdata = model.objects.filter(data_no=data_no, history=False)[0]
            data_id = omdata.id
        else:
            data_id = url_list[2]
    except:
        pass
    return render(request, "myform.html", locals())
Beispiel #6
0
def getColumnListAjax(request):
    '''
    get model column-list with permission
    input: request
    return: json
    author: Arthur
    '''
    username = request.user.username
    postdata = getPostdata(request)

    if username:
        require_field = ['model']
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            permission = "Omdata_" + postdata.get('model', '') + "_View"
            this_model = list(
                filter(
                    lambda x: x.__name__ == re.findall("^(.+)_View",
                                                       permission)[0],
                    apps.get_models()))
            result = {}

            #isPolicy = False
            from omflow.syscom.common import License
            version_type = License().getVersionType()
            if version_type != 'C':
                from ommonitor.models import MonitorFlow
                if len(this_model) == 0 and request.user.has_perm(
                        "OmMonitor_Manage"):
                    policy_model = list(
                        filter(
                            lambda x: x.__name__ == postdata.get('model', ''),
                            apps.get_models()))
                    if len(policy_model):
                        this_table_id = re.findall("OmPolicy_(.+)",
                                                   postdata.get('model',
                                                                ''))[0]
                        fa = list(
                            MonitorFlow.objects.filter(
                                table_id=this_table_id).values('flowobject'))
                        if len(fa):
                            fa = json.loads(fa[0]['flowobject'])
                            result["collector_id"] = "收集器ID"
                            for item in fa['items']:
                                if item['type'] == "end":
                                    for output in item['config']['output']:
                                        field_name = re.findall(
                                            '\$\((.+)\)', output['name'])[0]
                                        result[field_name] = output['des']

            if len(this_model) and request.user.has_perm(
                    str(this_model[0]._meta.app_label) + "." + permission):
                if re.match('Omdata_.+_View', permission):
                    flow_uuid = re.findall("Omdata_(.+)_View", permission)[
                        0]  #Omdata_5d3c2cbdcf4145c3a05affaf4a74345b_View
                    fa = FlowActiveGlobalObject.UUIDSearch(
                        flow_uuid).merge_formobject
                    if len(fa):
                        fa = json.loads(fa)
                        for field in this_model[0]._meta.fields:
                            if 'formitm' in field.verbose_name:
                                if field.name.upper() in fa:
                                    if fa[field.name.upper(
                                    )]["type"] == 'h_group':
                                        #result[field.name] = fa[field.name.upper]
                                        result[
                                            field.name] = fa[field.name.upper(
                                            )]["config"]["group_title"]
                                    else:
                                        result[
                                            field.name] = fa[field.name.upper(
                                            )]["config"]["title"]
                            else:
                                result[field.name] = field.verbose_name

                    lang = get_language()
                    app_id = FlowActiveGlobalObject.UUIDSearch(
                        flow_uuid).flow_app_id
                    result = Translator('single_app', 'active', lang, app_id,
                                        None).Do(result)

            if result != {}:
                info('%s get Column-List success' % username, request)
                return ResponseAjax(statusEnum.success, _('讀取成功。'),
                                    result).returnJSON()
            else:
                info('%s get Column-List with no permission' % username,
                     request)
                return ResponseAjax(statusEnum.no_permission,
                                    _('您沒有權限進行此操作。')).returnJSON()
        else:
            info('%s get Column-List error' % username, request)
            return ResponseAjax(statusEnum.not_found, checker.get('message'),
                                checker).returnJSON()
    else:
        info('%s get Column-List with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Beispiel #7
0
def listMyMissionAjax(request):
    '''
    list my missions.
    input: request
    return: json
    author: Kolin Hsu
    '''
    #get post data
    postdata = getPostdata(request)
    omflow_restapi = postdata.get('omflow_restapi', '')
    if not omflow_restapi:
        ticket_createtime = postdata.get('ticket_createtime', '')
        ticket_createtime = ticket_createtime.split(',')
        field_list = [
            'title__icontains', 'flow_name__icontains', 'status__icontains',
            'create_user_id__nick_name__icontains'
        ]
        display_field = [
            'flow_name', 'flow_uuid', 'level', 'status', 'title',
            'create_user_id__nick_name', 'assign_group_id__display_name',
            'assignee_id__nick_name', 'ticket_createtime', 'data_id',
            'data_no', 'action', 'attachment'
        ]
        group_id_list = list(request.user.groups.all().values_list('id',
                                                                   flat=True))
        query = Missions.objects.filter(
            (Q(assignee_id=request.user.id)
             | (Q(assign_group_id__in=group_id_list) & Q(assignee_id=None)))
            & Q(history=False) & Q(ticket_createtime__range=ticket_createtime)
            & Q(is_active=True) & Q(deploy_flag=True)).values(*display_field)
        result = DatatableBuilder(request, query, field_list)

        #載入語言包
        language = get_language()
        data = result['data']
        if isinstance(data, str):
            pass
        elif isinstance(data, list) or isinstance(data, dict):
            for key_or_line in data:
                if isinstance(data, list):
                    line = key_or_line
                else:
                    line = data[key_or_line]
                fa = FlowActiveGlobalObject.UUIDSearch(line['flow_uuid'])
                if fa:
                    app_id = fa.flow_app_id
                    for key in line:
                        if key in ['flow_name', 'level', 'status']:
                            line[key] = Translator('single_app', 'active',
                                                   language, app_id,
                                                   None).Do(line[key])
                        elif key == 'action':
                            action = line[key]
                            if action:
                                action1 = action.split(',')[0]
                                action2 = action.split(',')[1]
                                trans_a1 = Translator('single_app', 'active',
                                                      language, app_id,
                                                      None).Do(action1)
                                trans_a2 = Translator('single_app', 'active',
                                                      language, app_id,
                                                      None).Do(action2)
                                line[key] = trans_a1 + ',' + trans_a2


#         result['data'] = Translator('datatable_multi_app', 'active', language, None, None).Do(result['data'])

        info('%s list Mission success.' % request.user.username, request)
        return JsonResponse(result)
    else:
        #api使用
        group_id_list = list(request.user.groups.all().values_list('id',
                                                                   flat=True))
        query = Missions.objects.filter((Q(assignee_id=request.user.id) | (
            Q(assign_group_id__in=group_id_list) & Q(assignee_id=None)))
                                        & Q(history=False) & Q(is_active=True)
                                        & Q(deploy_flag=True))
        result = listQueryBuilder(None, postdata, query)
        if result['status']:
            info('%s list Mission success.' % request.user.username, request)
            return ResponseAjax(statusEnum.success, result['message'],
                                result['result']).returnJSON()
        else:
            info('%s list Mission error.' % request.user.username, request)
            return ResponseAjax(statusEnum.not_found,
                                result['message']).returnJSON()