def add_entity_uuids(self, submission: Submission): worksheets = {} col_idx = 1 entities = [ entity for entity in submission.get_entities() if entity.spreadsheet_location ] for entity in entities: worksheet_title = entity.spreadsheet_location.get( 'worksheet_title') row_index = entity.spreadsheet_location.get('row_index') if not worksheets.get(worksheet_title): worksheet = self.workbook[worksheet_title] ingest_worksheet = IngestWorksheet(worksheet=worksheet) worksheets[worksheet_title] = ingest_worksheet column_header = f'{entity.concrete_type}.uuid' if column_header not in ingest_worksheet.get_column_headers(): ingest_worksheet.insert_column_with_header( column_header, col_idx) ingest_worksheet = worksheets.get(worksheet_title) ingest_worksheet.cell(row=row_index, column=col_idx).value = entity.uuid
def test_get_column_headers_includes_blank_cells(self): # given: header_row = 4 rows = [['name', 'address', '', 'email']] worksheet = spreadsheet_utils.create_worksheet('person', rows, start_row=header_row) # when: ingest_worksheet = IngestWorksheet(worksheet, header_row_idx=header_row) column_headers = ingest_worksheet.get_column_headers() # then: self.assertEqual(len(column_headers), 4) self.assertEqual(column_headers, ['name', 'address', '', 'email'])
def create_row_template(self, ingest_worksheet: IngestWorksheet): concrete_type = self.get_concrete_type(ingest_worksheet.title) domain_type = self.get_domain_type(concrete_type) column_headers = ingest_worksheet.get_column_headers() cell_conversions = [] context = self._determine_context(concrete_type, ingest_worksheet) header_counter = {} for header in column_headers: if not header_counter.get(header): header_counter[header] = 0 header_counter[header] = header_counter[header] + 1 column_spec = column_specification.look_up(self.template, header, concrete_type, context=context, order_of_occurrence=header_counter[header]) strategy = conversion_strategy.determine_strategy(column_spec) cell_conversions.append(strategy) default_values = self._define_default_values(concrete_type) return RowTemplate(domain_type, concrete_type, cell_conversions, default_values=default_values)