示例#1
0
def editor(request, is_mobile=False, is_embeddable=False):
    editor_id = request.GET.get('editor')
    editor_type = request.GET.get('type', 'hive')
    gist_id = request.GET.get('gist')

    if editor_type == 'notebook' or request.GET.get('notebook'):
        return notebook(request)

    if editor_type == 'gist':
        gist_doc = _get_gist_document(uuid=gist_id)
        editor_type = gist_doc.extra

    if EXAMPLES.AUTO_OPEN.get() and not editor_id:
        sample_query = _get_dialect_example(dialect=editor_type)
        if sample_query:
            editor_id = sample_query.id

    if editor_id and not gist_id:  # Open existing saved editor document
        editor_type = _get_editor_type(editor_id)

    template = 'editor.mako'
    if ENABLE_NOTEBOOK_2.get():
        template = 'editor2.mako'
    elif is_mobile:
        template = 'editor_m.mako'

    return render(
        template, request, {
            'editor_id':
            editor_id or None,
            'notebooks_json':
            '{}',
            'is_embeddable':
            request.GET.get('is_embeddable', False),
            'editor_type':
            editor_type,
            'options_json':
            json.dumps({
                'languages': get_ordered_interpreters(request.user),
                'mode': 'editor',
                'is_optimizer_enabled': has_optimizer(),
                'is_wa_enabled': has_workload_analytics(),
                'is_navigator_enabled': has_catalog(request.user),
                'editor_type': editor_type,
                'mobile': is_mobile
            })
        })
示例#2
0
def create_notebook(request):
    response = {'status': -1}

    editor_type = request.POST.get('type', 'notebook')
    gist_id = request.POST.get('gist')
    directory_uuid = request.POST.get('directory_uuid')
    is_blank = request.POST.get('blank', 'false') == 'true'

    if gist_id:
        gist_doc = _get_gist_document(uuid=gist_id)
        statement = json.loads(gist_doc.data)['statement']

        editor = make_notebook(name='',
                               description='',
                               editor_type=editor_type,
                               statement=statement,
                               is_presentation_mode=True)
    else:
        editor = Notebook()

        if EXAMPLES.AUTO_OPEN.get() and not is_blank:
            document = _get_dialect_example(dialect=editor_type)
            if document:
                editor = Notebook(document=document)
                editor = upgrade_session_properties(request, editor)

    data = editor.get_data()

    if editor_type != 'notebook':
        data['name'] = ''
        data[
            'type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types

    data['directoryUuid'] = directory_uuid
    editor.data = json.dumps(data)

    response['notebook'] = editor.get_data()
    response['status'] = 0

    return JsonResponse(response)