예제 #1
0
파일: views.py 프로젝트: ztwu/hue
def download(request):
    if not ENABLE_DOWNLOAD.get():
        return serve_403_error(request)

    notebook = json.loads(request.POST.get('notebook', '{}'))
    snippet = json.loads(request.POST.get('snippet', '{}'))
    file_format = request.POST.get('format', 'csv')

    response = get_api(request, snippet).download(
        notebook,
        snippet,
        file_format,
        user_agent=request.META.get('HTTP_USER_AGENT'))

    if response:
        request.audit = {
            'operation':
            'DOWNLOAD',
            'operationText':
            'User %s downloaded results from %s as %s' %
            (request.user.username, _get_snippet_name(notebook), file_format),
            'allowed':
            True
        }

    return response
예제 #2
0
def download(request):
    if not ENABLE_DOWNLOAD.get():
        return serve_403_error(request)

    try:
        file_format = 'csv' if 'csv' == request.POST.get(
            'type') else 'xls' if 'xls' == request.POST.get('type') else 'json'
        facet = json.loads(request.POST.get('facet', '{}'))

        json_response = search(request)
        response = json.loads(json_response.content)

        if facet:
            response['response']['docs'] = response['normalized_facets'][0][
                'docs']
            collection = facet
            if not collection['template']['fieldsSelected']:
                facet['fields'] = facet['template']['fieldsAttributes']
        else:
            collection = json.loads(request.POST.get('collection', '{}'))

        if file_format == 'json':
            docs = response['response']['docs']
            resp = JsonResponse(docs, safe=False)
            resp['Content-Disposition'] = 'attachment; filename="%s.%s"' % (
                'query_result', file_format)
            return resp
        else:
            return export_download(
                response,
                file_format,
                collection,
                user_agent=request.META.get('HTTP_USER_AGENT'))
    except Exception as e:
        raise PopupException(_("Could not download search results: %s") % e)
예제 #3
0
def download(request):
  if not ENABLE_DOWNLOAD.get():
    return serve_403_error(request)

  notebook = json.loads(request.POST.get('notebook', '{}'))
  snippet = json.loads(request.POST.get('snippet', '{}'))
  file_format = request.POST.get('format', 'csv')
  user_agent = request.META.get('HTTP_USER_AGENT')
  file_name = _get_snippet_name(notebook)

  content_generator = get_api(request, snippet).download(notebook, snippet, file_format=file_format)
  response = export_csvxls.make_response(content_generator, file_format, file_name, user_agent=user_agent)

  if snippet['id']:
    response.set_cookie(
      'download-%s' % snippet['id'],
      json.dumps({
        'truncated': 'false',
        'row_counter': '0'
      }),
      max_age=DOWNLOAD_COOKIE_AGE
    )
  if response:
    request.audit = {
      'operation': 'DOWNLOAD',
      'operationText': 'User %s downloaded results from %s as %s' % (request.user.username, _get_snippet_name(notebook), file_format),
      'allowed': True
    }

  return response
예제 #4
0
def download(request, id, format, user_agent=None):
  if not ENABLE_DOWNLOAD.get():
    return serve_403_error(request)

  try:
    query_history = authorized_get_query_history(request, id, must_exist=True)
    db = dbms.get(request.user, query_history.get_query_server_config())
    LOG.debug('Download results for query %s: [ %s ]' % (query_history.server_id, query_history.query))

    return data_export.download(query_history.get_handle(), format, db, user_agent=user_agent)
  except Exception, e:
    if not hasattr(e, 'message') or not e.message:
      message = e
    else:
      message = e.message
    raise PopupException(message, detail='')
예제 #5
0
파일: views.py 프로젝트: cloudera/hue
def download(request, id, format, user_agent=None):
  if not ENABLE_DOWNLOAD.get():
    return serve_403_error(request)

  try:
    query_history = authorized_get_query_history(request, id, must_exist=True)
    db = dbms.get(request.user, query_history.get_query_server_config())
    LOG.debug('Download results for query %s: [ %s ]' % (query_history.server_id, query_history.query))

    return data_export.download(query_history.get_handle(), format, db, user_agent=user_agent)
  except Exception, e:
    if not hasattr(e, 'message') or not e.message:
      message = e
    else:
      message = e.message
    raise PopupException(message, detail='')
예제 #6
0
def get_desktop_enable_download():
    """Get desktop enable_download default"""
    return ENABLE_DOWNLOAD.get()
예제 #7
0
파일: conf.py 프로젝트: lorelib/hue
def get_desktop_enable_download():
  """Get desktop enable_download default"""
  return ENABLE_DOWNLOAD.get()