def _bulk_case_upload_api(request, domain): upload_file, case_type, search_field, create_new_cases, search_column = _get_bulk_case_upload_args_from_request( request, domain) case_upload, context = _process_file_and_get_upload( upload_file, request, domain) case_upload.check_file() with case_upload.get_spreadsheet() as spreadsheet: columns = spreadsheet.get_header_columns() excel_fields = columns # hide search column and matching case fields from the update list if search_column in excel_fields: excel_fields.remove(search_column) custom_fields = [] case_fields = [] #populate field arrays for f in excel_fields: if f == "name": custom_fields.append("") case_fields.append(f) else: custom_fields.append(f) case_fields.append("") config = importer_util.ImporterConfig(couch_user_id=request.couch_user._id, excel_fields=excel_fields, case_fields=case_fields, custom_fields=custom_fields, search_column=search_column, case_type=case_type, search_field=search_field, create_new_cases=create_new_cases) case_upload.trigger_upload(domain, config) return json_response({"msg": "success"})
def _bulk_case_upload_api(request, domain): try: upload_file = request.FILES["file"] case_type = request.POST["case_type"] if not upload_file or not case_type: raise Exception except Exception: raise ImporterError("Invalid POST request. " "Both 'file' and 'case_type' are required") search_field = request.POST.get('search_field', 'case_id') create_new_cases = request.POST.get('create_new_cases') == 'on' if search_field == 'case_id': default_search_column = 'case_id' elif search_field == 'external_id': default_search_column = 'external_id' else: raise ImporterError("Illegal value for search_field: %s" % search_field) search_column = request.POST.get('search_column', default_search_column) name_column = request.POST.get('name_column', 'name') upload_comment = request.POST.get('comment') case_upload, context = _process_file_and_get_upload( upload_file, request, domain) case_upload.check_file() with case_upload.get_spreadsheet() as spreadsheet: columns = spreadsheet.get_header_columns() excel_fields = columns # hide search column and matching case fields from the update list if search_column in excel_fields: excel_fields.remove(search_column) custom_fields = [] case_fields = [] #Create the field arrays for the importer in the same format #as the "Step 2" Web UI from the manual process for f in excel_fields: if f == name_column: custom_fields.append("") case_fields.append("name") else: custom_fields.append(f) case_fields.append("") config = importer_util.ImporterConfig(couch_user_id=request.couch_user._id, excel_fields=excel_fields, case_fields=case_fields, custom_fields=custom_fields, search_column=search_column, case_type=case_type, search_field=search_field, create_new_cases=create_new_cases) case_upload.trigger_upload(domain, config, comment=upload_comment) upload_id = case_upload.upload_id status_url = absolute_reverse('case_importer_upload_status', args=(domain, upload_id)) return json_response({ "code": 200, "message": "success", "status_url": status_url })