Example #1
0
def SubQueryDataAjax(request):
    '''
    load omdata.
    input: request
    return: json
    author: Kolin Hsu
    '''
    #function variable
    require_field = ['app_name', 'flow_name', 'data_id']
    #server side rule check
    postdata = getPostdata(request)
    checker = DataChecker(postdata, require_field)
    #get post data
    app_name = postdata.get('app_name', '')
    flow_name = postdata.get('flow_name', '')
    data_id = postdata.get('data_id', '')
    field_list = postdata.get('fields', [])
    service_id = postdata.get('service_id', [])

    if True:
        if checker.get('status') == 'success':
            #get model
            fa = FlowActiveGlobalObject.NameSearch(flow_name, None, app_name)
            omdata_model = getModel('omformmodel',
                                    'Omdata_' + fa.flow_uuid.hex)
            #整理欄位
            new_field_list = []
            group_user = []
            group_user_id = None
            for f in field_list:
                if re.match(r'formitm_[0-9]+-.+', f):
                    group_user_id = re.findall(r'(.+)-.+', f)[0]
                    group_user.append(f)
                    new_field_list.append(group_user_id)
                else:
                    new_field_list.append(f)

            #取得資料
            omdata = list(
                omdata_model.objects.filterformat(*new_field_list, id=data_id))

            if omdata:
                result = omdata[0]
                if group_user_id:
                    group_user_dict = json.loads(result.pop(group_user_id))
                    for g_u in group_user:
                        key = re.findall(r'.+-(.+)', g_u)[0]
                        result[g_u] = group_user_dict.get(key, '')
            else:
                result = {}

            info('%s load OmData success.' % request.user.username, request)
            return ResponseAjax(statusEnum.success, _('讀取成功。'),
                                result).returnJSON()
        else:
            info(
                '%s missing some require variable or the variable type error.'
                % request.user.username, request)
            return ResponseAjax(statusEnum.not_found, checker.get('message'),
                                checker).returnJSON()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Example #2
0
    mail_info = get_email(num, conn)
    mail_from = mail_info["From"]
    mail_subject = mail_info["Subject"]
    mail_content = mail_info["Body"]
    unseen_mails.append(mail_info)
#         print(mail_from)
#         print(mail_subject)
#         print(mail_content)
conn.close()
conn.logout()

#-----------------------------------------Submit Ticket--------------------------------------------#
from omformflow.views import createOmData
from omflow.global_obj import FlowActiveGlobalObject
try:
    fa = FlowActiveGlobalObject.NameSearch("事故管理", None, "服務管理")
    event_uuid = fa.flow_uuid.hex
    para_list = receive_keyword.split(',')
    for mail_info in unseen_mails:
        param = {}
        mail_from = mail_info["From"]
        mail_subject = mail_info["Subject"]
        mail_content = mail_info["Body"]
        #如果type = ['h_group','h_title','h_status','h_level']
        #{"id":"title","value":mail_subject,"type":"titile"}
        #{"id":"status","value":<text>,"type":"status"}
        #---------------------------------------------------
        #{"id":"FORMITM_4","value":0,"type":"h_status"},\
        #{"id":"status","value":'new',"type":"status"},\
        if [item for item in para_list if item in mail_subject
            ] and not ("Re:" in mail_subject or "RE:" in mail_subject):
Example #3
0
def SubQueryHeaderAjax(request):
    '''
    list omdata for subquery.
    input: request
    return: json
    author: Kolin Hsu
    '''
    #function variable
    display_field_list = [
        'id', 'data_no', 'stop_uuid', 'stop_chart_text', 'error',
        'error_message', 'closed', 'running'
    ]
    #get post data
    postdata = getPostdata(request)
    app_name = postdata.get('app_name', '')
    flow_name = postdata.get('flow_name', '')
    condition = postdata.get('condition', [])
    service_id = postdata.get('service_id', [])
    flowactive = FlowActiveGlobalObject.NameSearch(flow_name, None, app_name)
    flow_uuid = flowactive.flow_uuid.hex

    if True:
        #get field setting
        display_field_dict = json.loads(flowactive.display_field)
        for key in display_field_dict:
            if '-' in key:
                key = 'group'
            if key == 'create_user_id' or key == 'create_user':
                key = 'create_user_id__nick_name'
            elif key == 'update_user_id' or key == 'update_user':
                key = 'update_user_id__nick_name'
            display_field_list.append(key)
        search_field_list = display_field_list.copy()
        #暫時先使用display_field當作search_field
        field_list = list(
            map(lambda search_field: search_field + '__icontains',
                search_field_list))

        #sp conditions
        search_conditions = [{
            'column': 'history',
            'condition': '=',
            'value': False
        }]
        exclude_conditions = []
        for con in condition:
            if con['condition'] == '!=':
                con['condition'] = '='
                exclude_conditions.append(con)
            elif con['condition'] == 'exclude':
                con['condition'] = 'contains'
                exclude_conditions.append(con)
            else:
                search_conditions.append(con)

        sc = searchConditionBuilder(search_conditions)
        ec = searchConditionBuilder(exclude_conditions)
        #get model
        omdata_model = getModel('omformmodel', 'Omdata_' + flow_uuid)
        if ec:
            query = omdata_model.objects.filter(
                reduce(operator.and_,
                       sc)).exclude(reduce(operator.and_,
                                           ec)).values(*display_field_list)
        else:
            query = omdata_model.objects.filter(reduce(
                operator.and_, sc)).values(*display_field_list)

        result = DatatableBuilder(request, query, field_list)

        #轉換字與值
        result['data'] = datatableValueToText(result['data'], flow_uuid)

        #載入語言包
        language = get_language()
        result['data'] = Translator('datatable_single_app', 'active', language,
                                    flowactive.flow_app_id,
                                    None).Do(result['data'])

        info(request, '%s list OmData success.' % request.user.username)
        return JsonResponse(result)
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()