def open_notebook(request): response = {'status': -1} notebook_id = request.GET.get('notebook') notebook = Notebook(document=Document2.objects.get(id=notebook_id)) notebook = upgrade_session_properties(request, notebook) response['status'] = 0 response['notebook'] = notebook.get_json() response['message'] = _('Notebook loaded successfully')
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)
def _get_document_helper(request, uuid, with_data, with_dependencies, path): if uuid: if uuid.isdigit(): document = Document2.objects.document(user=request.user, doc_id=uuid) else: document = Document2.objects.get_by_uuid(user=request.user, uuid=uuid) else: # Find by path document = Document2.objects.get_by_path(user=request.user, path=path) response = { 'document': document.to_dict(), 'parent': document.parent_directory.to_dict() if document.parent_directory else None, 'children': [], 'dependencies': [], 'dependents': [], 'data': '', 'status': 0 } response['user_perms'] = { 'can_read': document.can_read(request.user), 'can_write': document.can_write(request.user) } if with_data: data = json.loads(document.data) # Upgrade session properties for Hive and Impala if document.type.startswith('query'): from notebook.models import upgrade_session_properties notebook = Notebook(document=document) notebook = upgrade_session_properties(request, notebook) data = json.loads(notebook.data) if document.type == 'query-pig': # Import correctly from before Hue 4.0 properties = data['snippets'][0]['properties'] if 'hadoopProperties' not in properties: properties['hadoopProperties'] = [] if 'parameters' not in properties: properties['parameters'] = [] if 'resources' not in properties: properties['resources'] = [] if data.get('uuid') != document.uuid: # Old format < 3.11 data['uuid'] = document.uuid response['data'] = data if with_dependencies: response['dependencies'] = [ dependency.to_dict() for dependency in document.dependencies.all() ] response['dependents'] = [ dependent.to_dict() for dependent in document.dependents.exclude( is_history=True).all() ] # Get children documents if this is a directory if document.is_directory: directory = Directory.objects.get(id=document.id) # If this is the user's home directory, fetch shared docs too if document.is_home_directory: children = directory.get_children_and_shared_documents( user=request.user) response.update( _filter_documents(request, queryset=children, flatten=True)) else: children = directory.get_children_documents() response.update( _filter_documents(request, queryset=children, flatten=False)) # Paginate and serialize Results if 'documents' in response: response.update(_paginate(request, queryset=response['documents'])) # Rename documents to children response['children'] = response.pop('documents') response['children'] = [doc.to_dict() for doc in response['children']] return response