Пример #1
0
def get_preview():
    """Summary

    Returns
    -------
    json
        preview: list of result preview
        header: result header
        error: True if error, else False
        errorMessage: the error message of error, else an empty string
    """
    try:
        file_id = request.get_json()["fileId"]
        result_info = {"id": file_id}
        result = Result(current_app, session, result_info)
        headers, preview = result.get_file_preview()

    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return jsonify({
            'preview': [],
            'header': [],
            'id': file_id,
            'error': True,
            'errorMessage': str(e)
        }), 500

    return jsonify({
        'preview': preview,
        'header': headers,
        'id': file_id,
        'error': False,
        'errorMessage': ''
    })
Пример #2
0
def get_preview():
    """Summary

    Returns
    -------
    json
        preview: list of result preview
        header: result header
        error: True if error, else False
        errorMessage: the error message of error, else an empty string
    """
    try:
        data = request.get_json()
        if not (data and data.get("fileId")):
            return jsonify({
                'preview': [],
                'header': [],
                'id': None,
                'error': True,
                'errorMessage': "Missing file Id"
            }), 400

        file_id = data["fileId"]
        result_info = {"id": file_id}
        result = Result(current_app, session, result_info)
        if not result:
            return jsonify({
                'preview': [],
                'header': [],
                'id':
                file_id,
                'error':
                True,
                'errorMessage':
                "You do not have access to this query"
            }), 401

        headers, preview = result.get_file_preview()

    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return jsonify({
            'preview': [],
            'header': [],
            'id': file_id,
            'error': True,
            'errorMessage': str(e)
        }), 500

    return jsonify({
        'preview': preview,
        'header': headers,
        'id': file_id,
        'error': False,
        'errorMessage': ''
    })