예제 #1
0
파일: api.py 프로젝트: sandredd/hue-1
def save_query(request, design_id=None):
    response = {'status': -1, 'message': ''}

    if request.method != 'POST':
        response['message'] = _('A POST request is required.')

    app_name = get_app_name(request)
    query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]
    design = safe_get_design(request, query_type, design_id)

    try:
        save_form = SaveForm(request.POST.copy())
        query_form = get_query_form(request, design_id)

        if query_form.is_valid() and save_form.is_valid():
            design = save_design(request, save_form, query_form, query_type,
                                 design, True)
            response['design_id'] = design.id
            response['status'] = 0
        else:
            response['errors'] = query_form.errors
    except RuntimeError as e:
        response['message'] = str(e)

    return JsonResponse(response)
예제 #2
0
파일: api.py 프로젝트: sandredd/hue-1
def execute_query(request, design_id=None):
    response = {'status': -1, 'message': ''}

    if request.method != 'POST':
        response['message'] = _('A POST request is required.')

    app_name = get_app_name(request)
    query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]
    design = safe_get_design(request, query_type, design_id)

    try:
        form = get_query_form(request, design_id)

        if form.is_valid():
            design = save_design(request, SaveForm(), form, query_type, design)

            query = SQLdesign(form, query_type=query_type)
            query_server = dbms.get_query_server_config(
                request.POST.get('server'))
            db = dbms.get(request.user, query_server)
            query_history = db.execute_query(query, design)
            query_history.last_state = beeswax_models.QueryHistory.STATE.expired.value
            query_history.save()

            try:
                db.use(form.cleaned_data['database'])
                datatable = db.execute_and_wait(query)
                results = db.client.create_result(datatable)

                response['status'] = 0
                response['results'] = results_to_dict(results)
                response['design'] = design.id
            except Exception as e:
                response['status'] = -1
                response['message'] = str(e)

        else:
            response['message'] = _('There was an error with your query.')
            response['errors'] = form.errors
    except RuntimeError as e:
        response['message'] = str(e)

    return JsonResponse(response, encoder=ResultEncoder)
예제 #3
0
파일: api.py 프로젝트: gitluochao/hue
def save_query(request, design_id=None):
  response = {'status': -1, 'message': ''}

  if request.method != 'POST':
    response['message'] = _('A POST request is required.')

  app_name = get_app_name(request)
  query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]
  design = safe_get_design(request, query_type, design_id)

  try:
    save_form = SaveForm(request.POST.copy())
    query_form = get_query_form(request, design_id)

    if query_form.is_valid() and save_form.is_valid():
      design = save_design(request, save_form, query_form, query_type, design, True)
      response['design_id'] = design.id
      response['status'] = 0
    else:
      response['errors'] = query_form.errors
  except RuntimeError, e:
    response['message'] = str(e)
예제 #4
0
파일: api.py 프로젝트: ronglei/hue
def save_query(request, design_id=None):
    response = {"status": -1, "message": ""}

    if request.method != "POST":
        response["message"] = _("A POST request is required.")

    app_name = get_app_name(request)
    query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]
    design = safe_get_design(request, query_type, design_id)

    try:
        save_form = SaveForm(request.POST.copy())
        query_form = get_query_form(request, design_id)

        if query_form.is_valid() and save_form.is_valid():
            design = save_design(request, save_form, query_form, query_type, design, True)
            response["design_id"] = design.id
            response["status"] = 0
        else:
            response["errors"] = query_form.errors
    except RuntimeError, e:
        response["message"] = str(e)
예제 #5
0
파일: api.py 프로젝트: gitluochao/hue
def execute_query(request, design_id=None):
  response = {'status': -1, 'message': ''}

  if request.method != 'POST':
    response['message'] = _('A POST request is required.')
  
  app_name = get_app_name(request)
  query_type = beeswax_models.SavedQuery.TYPES_MAPPING[app_name]
  design = safe_get_design(request, query_type, design_id)

  try:
    form = get_query_form(request, design_id)

    if form.is_valid():
      design = save_design(request, SaveForm(), form, query_type, design)

      query = SQLdesign(form, query_type=query_type)
      query_server = dbms.get_query_server_config(request.POST.get('server'))
      db = dbms.get(request.user, query_server)
      query_history = db.execute_query(query, design)
      query_history.last_state = beeswax_models.QueryHistory.STATE.expired.index
      query_history.save()

      try:
        db.use(form.cleaned_data['database'])
        datatable = db.execute_and_wait(query)
        results = db.client.create_result(datatable)

        response['status'] = 0
        response['results'] = results_to_dict(results)
        response['design'] = design.id
      except Exception, e:
        response['status'] = -1
        response['message'] = str(e)

    else: