def _test(self, get_special_fields, get_case_properties_for_case_type, special_fields, case_properties, excluded_fields, expected_result): get_special_fields.return_value = special_fields get_case_properties_for_case_type.return_value = case_properties self.assert_doc_lists_equal( get_suggested_case_fields('my-domain', 'my_case_type', exclude=excluded_fields), expected_result )
def _test(self, get_special_fields, get_case_properties_for_case_type, get_values_hints_dict, get_deprecated_fields, special_fields, case_properties, excluded_fields, expected_result): get_special_fields.return_value = special_fields get_case_properties_for_case_type.return_value = case_properties get_values_hints_dict.return_value = defaultdict(list) get_deprecated_fields.return_value = set() self.assert_doc_lists_equal( get_suggested_case_fields('my-domain', 'my_case_type', exclude=excluded_fields), expected_result )
def excel_fields(request, domain): """ Step two of three. Important values that are grabbed from the POST or defined by the user on this page: case_type: The type of case we are matching to. When creating new cases, this is the type they will be created as. When updating existing cases, this is the type that we will search for. If the wrong case type is used when looking up existing cases, we will not update them. create_new_cases: A boolean that controls whether or not the user wanted to create new cases for any case that doesn't have a matching case id in the upload. search_column: Which column of the Excel file we are using to specify either case ids or external ids. This is, strangely, required. If creating new cases only you would expect these to be blank with the create_new_cases flag set. search_field: Either case id or external id, determines which type of identification we are using to match to cases. """ case_type = request.POST['case_type'] try: search_column = request.POST['search_column'] except MultiValueDictKeyError: # this is only true if your configuration is messed up in an irreparable way messages.error( request, _('The Excel file you are trying to import does not have any headers.' )) return HttpResponseRedirect(base.ImportCases.get_url(domain)) search_field = request.POST['search_field'] create_new_cases = request.POST.get('create_new_cases') == 'on' case_upload = CaseUpload.get(request.session.get(EXCEL_SESSION_ID)) try: case_upload.check_file() except ImporterError as e: return render_error(request, domain, get_importer_error_message(e)) 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) field_specs = get_suggested_case_fields(domain, case_type, exclude=[search_field]) case_field_specs = [field_spec.to_json() for field_spec in field_specs] context = { 'case_type': case_type, 'search_column': search_column, 'search_field': search_field, 'create_new_cases': create_new_cases, 'columns': columns, 'excel_fields': excel_fields, 'case_field_specs': case_field_specs, 'domain': domain, } context.update( _case_importer_breadcrumb_context( _('Match Excel Columns to Case Properties'), domain)) return render(request, "case_importer/excel_fields.html", context)
def excel_fields(request, domain): """ Step two of three. Important values that are grabbed from the POST or defined by the user on this page: case_type: The type of case we are matching to. When creating new cases, this is the type they will be created as. When updating existing cases, this is the type that we will search for. If the wrong case type is used when looking up existing cases, we will not update them. create_new_cases: A boolean that controls whether or not the user wanted to create new cases for any case that doesn't have a matching case id in the upload. search_column: Which column of the excel file we are using to specify either case ids or external ids. This is, strangely, required. If creating new cases only you would expect these to be blank with the create_new_cases flag set. search_field: Either case id or external id, determines which type of identification we are using to match to cases. """ case_type = request.POST['case_type'] try: search_column = request.POST['search_column'] except MultiValueDictKeyError: # this is only true if your configuration is messed up in an irreparable way messages.error(request, _('It looks like you may have accessed this page from a stale page. ' 'Please start over.')) return _spreadsheet_expired(request, domain) search_field = request.POST['search_field'] create_new_cases = request.POST.get('create_new_cases') == 'on' case_upload = CaseUpload.get(request.session.get(EXCEL_SESSION_ID)) try: case_upload.check_file() except ImporterError as e: return render_error(request, domain, get_importer_error_message(e)) 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) field_specs = get_suggested_case_fields( domain, case_type, exclude=[search_field]) case_field_specs = [field_spec.to_json() for field_spec in field_specs] return render( request, "case_importer/excel_fields.html", { 'case_type': case_type, 'search_column': search_column, 'search_field': search_field, 'create_new_cases': create_new_cases, 'columns': columns, 'excel_fields': excel_fields, 'case_field_specs': case_field_specs, 'domain': domain, 'report': { 'name': 'Import: Match columns to fields' }, 'slug': base.ImportCases.slug } )