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)
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)
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)
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)
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: