def ajax_add_hs_res(request): return_obj = {"success": False, "message": None, "results": {}} if request.is_ajax() and request.method == "GET": if not request.GET.get("res_id"): return_obj["message"] = message_template_param_unfilled.format(param="res_id") else: res_id = request.GET["res_id"] res_type = None res_title = None if request.GET.get("res_type"): res_type = request.GET["res_type"] if request.GET.get("res_title"): res_title = request.GET["res_title"] r = get_hs_auth_obj(request) if not r["success"]: return_obj["message"] = r["message"] return return_obj else: hs = r["hs_obj"] r = validate_res_request(hs, res_id) if not r["can_access"]: return_obj["message"] = r["message"] else: res_layers_obj_list = get_res_layers_from_db(hs, res_id, res_type, res_title, request.user.username) if res_layers_obj_list: return_obj["results"] = res_layers_obj_list return_obj["success"] = True else: return_obj = process_nongeneric_res(hs, res_id, res_type, res_title, request.user.username) else: return_obj["message"] = message_template_wrong_req_method.format(method="GET") return JsonResponse(return_obj)
def ajax_add_generic_res_file(request): return_obj = {'success': False, 'message': None, 'results': {}} if request.is_ajax() and request.method == 'GET': if not request.GET.get('res_id'): return_obj['message'] = message_template_param_unfilled.format( param='res_id') else: res_id = request.GET['res_id'] if not request.GET.get('res_fname'): return_obj['message'] = message_template_param_unfilled.format( param='res_fname') else: res_fname = request.GET['res_fname'] file_index = int(request.GET['file_index']) r = get_hs_auth_obj(request) if not r['success']: return_obj['message'] = r['message'] return return_obj else: hs = r['hs_obj'] r = validate_res_request(hs, res_id) if not r['can_access']: return_obj['message'] = r['message'] else: generic_file_layer_obj = get_generic_file_layer_from_db( hs, res_id, res_fname, file_index, request.user.username) if generic_file_layer_obj: return_obj['results'] = generic_file_layer_obj return_obj['success'] = True else: return_obj = process_generic_res_file( hs, res_id, res_fname, request.user.username, file_index) else: return_obj['message'] = message_template_wrong_req_method.format( method="GET") return JsonResponse(return_obj)
def ajax_add_hs_res(request): return_obj = {'success': False, 'message': None, 'results': {}} if request.is_ajax() and request.method == 'GET': if not request.GET.get('res_id'): return_obj['message'] = message_template_param_unfilled.format( param='res_id') else: res_id = request.GET['res_id'] res_type = None res_title = None if request.GET.get('res_type'): res_type = request.GET['res_type'] if request.GET.get('res_title'): res_title = request.GET['res_title'] r = get_hs_auth_obj(request) if not r['success']: return_obj['message'] = r['message'] return return_obj else: hs = r['hs_obj'] r = validate_res_request(hs, res_id) if not r['can_access']: return_obj['message'] = r['message'] else: res_layers_obj_list = get_res_layers_from_db( hs, res_id, res_type, res_title, request.user.username) if res_layers_obj_list: return_obj['results'] = res_layers_obj_list return_obj['success'] = True else: return_obj = process_nongeneric_res( hs, res_id, res_type, res_title, request.user.username) else: return_obj['message'] = message_template_wrong_req_method.format( method="GET") return JsonResponse(return_obj)
def ajax_add_generic_res_file(request): return_obj = {"success": False, "message": None, "results": {}} if request.is_ajax() and request.method == "GET": if not request.GET.get("res_id"): return_obj["message"] = message_template_param_unfilled.format(param="res_id") else: res_id = request.GET["res_id"] if not request.GET.get("res_fname"): return_obj["message"] = message_template_param_unfilled.format(param="res_fname") else: res_fname = request.GET["res_fname"] file_index = int(request.GET["file_index"]) r = get_hs_auth_obj(request) if not r["success"]: return_obj["message"] = r["message"] return return_obj else: hs = r["hs_obj"] r = validate_res_request(hs, res_id) if not r["can_access"]: return_obj["message"] = r["message"] else: generic_file_layer_obj = get_generic_file_layer_from_db( hs, res_id, res_fname, file_index, request.user.username ) if generic_file_layer_obj: return_obj["results"] = generic_file_layer_obj return_obj["success"] = True else: return_obj = process_generic_res_file( hs, res_id, res_fname, request.user.username, file_index ) else: return_obj["message"] = message_template_wrong_req_method.format(method="GET") return JsonResponse(return_obj)