Beispiel #1
0
def saveServiceAjax(request):
    '''
    save manager's service setting
    input: request
    return: json
    author: Arthur
    '''
    #Server Side Rule Check
    username = request.user.username
    postdata = getPostdata(request)

    if username:
        require_field = ['content']
        checker = DataChecker(postdata, require_field)

        if checker.get('status') == 'success':

            #是否存入翻譯
            lan_package = postdata.get('lan_package', None)
            if lan_package:
                FlowActiveGlobalObject.setSysLanDict("service", None,
                                                     lan_package)

            #static variable
            box_object = json.loads(postdata.get('content', ''))
            OmServiceDesign.objects.create(
                content=json.dumps(box_object),
                language_package=json.dumps(
                    FlowActiveGlobalObject.getSysLanDict('service')))

            OmService.objects.all().delete()

            ServiceList = []
            for key in box_object["list"]:
                thisSer = box_object["list"][key]
                if thisSer["type"] == "service":
                    flow_uuid = FlowActiveGlobalObject.APIgetUUID(
                        thisSer['api_path'])
                    ser = OmService(service_id=thisSer['id'],
                                    flow_uuid=flow_uuid,
                                    role=thisSer['setting']['setRole'],
                                    default_value=json.dumps(
                                        thisSer['default_value']))
                    ServiceList.append(ser)

            OmService.objects.bulk_create(ServiceList)

            info('%s update Service success' % username, request)
            return ResponseAjax(statusEnum.success, _('儲存成功。')).returnJSON()
        else:
            info('%s update Service error' % username, request)
            return ResponseAjax(statusEnum.not_found, checker.get('message'),
                                checker).returnJSON()
    else:
        info('%s update Service with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Beispiel #2
0
def importTranslationAjax(request):
    '''
    import service language package
    input: request
    return: json
    author: Arthur
    '''
    #function variable
    require_field = ['language']
    #server side rule check
    postdata = getPostdata(request)
    language_str = postdata.get('language_list', '')
    language = postdata.get('language', '')
    checker = DataChecker(postdata, require_field)
    if checker.get('status') == 'success':
        #wa = WorkspaceApplication.objects.get(id=app_id)
        #language_dict = json.loads(wa.language_package)
        max = OmServiceDesign.objects.all().aggregate(Max('id')).get('id__max')
        this_service = OmServiceDesign.objects.get(id=max)
        language_dict = json.loads(this_service.language_package)

        temp_dict = {}
        language_list = language_str.split('\r\n')
        for line in language_list:
            if line:
                sp_index = line.find(':')
                if line[:sp_index] == 'original':
                    key = line[sp_index + 1:]
                else:
                    temp_dict[key] = line[sp_index + 1:]
        language_dict[language] = temp_dict
        language_str = json.dumps(language_dict)
        this_service.language_package = language_str
        this_service.save()
        #set global
        FlowActiveGlobalObject.setSysLanDict("service", language, temp_dict)
        info('%s import language package success.' % request.user.username,
             request)
        return ResponseAjax(statusEnum.success, _('匯入成功。')).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()