Esempio n. 1
0
def import_common_template(request):
    if not check_white_apps(request):
        return JsonResponse({
            'result':
            False,
            'message':
            'you have no permission to call this api.'
        })

    f = request.FILES.get('data_file', None)
    r = read_template_data_file(f)
    if not r['result']:
        return JsonResponse(r)

    override = BooleanField().to_python(request.POST.get('override', False))

    try:
        import_result = CommonTemplate.objects.import_templates(
            r['data']['template_data'], override)
    except Exception as e:
        logger.exception(e)
        return JsonResponse({
            'result':
            False,
            'message':
            'invalid flow data or error occur, please contact administrator'
        })

    return JsonResponse(import_result)
Esempio n. 2
0
def import_common_template(request):
    if not check_white_apps(request):
        return JsonResponse({
            'result':
            False,
            'message':
            'you have no permission to call this api.'
        })

    try:
        req_data = json.loads(request.body)
    except Exception:
        return JsonResponse({
            'result': False,
            'message': 'invalid param format'
        })

    template_data = req_data.get('template_data', None)
    if not template_data:
        return JsonResponse({
            'result': False,
            'message': 'template data can not be none'
        })
    r = read_encoded_template_data(template_data)
    if not r['result']:
        return JsonResponse(r)

    override = BooleanField().to_python(req_data.get('override', False))

    try:
        import_result = CommonTemplate.objects.import_templates(
            r['data']['template_data'], override)
    except Exception as e:
        logger.exception(e)
        return JsonResponse({
            'result':
            False,
            'message':
            'invalid flow data or error occur, please contact administrator'
        })

    return JsonResponse(import_result)