diff --git a/otlmow_template/SubsetTemplateCreator.py b/otlmow_template/SubsetTemplateCreator.py index 9fa06a1..9e872ee 100644 --- a/otlmow_template/SubsetTemplateCreator.py +++ b/otlmow_template/SubsetTemplateCreator.py @@ -100,6 +100,7 @@ def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to highlight_deprecated_attributes = kwargs.get('highlight_deprecated_attributes', False) amount_of_examples = kwargs.get('amount_of_examples', 0) wb = load_workbook(temporary_path) + wb.create_sheet('Keuzelijsten') # Volgorde is belangrijk! Eerst rijen verwijderen indien nodig dan choice list toevoegen, # staat namelijk vast op de kolom en niet het attribuut in die kolom if add_geo_artefact is False: @@ -227,7 +228,6 @@ def remove_geo_artefact_excel(cls, workbook): @classmethod def add_choice_list_excel(cls, workbook, instantiated_attributes: List, path_to_subset: Path): - workbook.create_sheet('Keuzelijsten') choice_list_dict = {} dotnotation_module = DotnotationHelper() for sheet in workbook: @@ -294,22 +294,13 @@ def add_mock_data_excel(cls, workbook, rows_of_examples: int): cell.value = mock_values[cell.column - 1] @classmethod - def remove_geo_artefact_csv(cls, reader, new_file): - delimiter = ';' - header = [] - data = [] - for row_nr, row in enumerate(reader): - if row_nr == 0: - header = row - else: - data = row - + def remove_geo_artefact_csv(cls, header, data): if 'geometry' in header: deletion_index = header.index('geometry') header.remove('geometry') - data.pop(deletion_index) - new_file.write(delimiter.join(header) + '\n') - new_file.write(delimiter.join(data) + '\n') + for d in data: + d.pop(deletion_index) + return [header, data] @classmethod def multiple_csv_template(cls, path_to_template_file_and_extension, path_to_subset, temporary_path, @@ -332,6 +323,8 @@ def multiple_csv_template(cls, path_to_template_file_and_extension, path_to_subs @classmethod def alter_csv_template(cls, path_to_template_file_and_extension, path_to_subset, temporary_path, instantiated_attributes, **kwargs): + header = [] + data = [] delimiter = ';' add_geo_artefact = kwargs.get('add_geo_artefact', False) add_attribute_info = kwargs.get('add_attribute_info', False) @@ -339,17 +332,24 @@ def alter_csv_template(cls, path_to_template_file_and_extension, path_to_subset, with open(temporary_path, 'r+', encoding='utf-8') as csvfile: new_file = open(path_to_template_file_and_extension, 'w', encoding='utf-8') reader = csv.reader(csvfile, delimiter=delimiter, quotechar=quote_char) + for row_nr, row in enumerate(reader): + if row_nr == 0: + header = row + else: + data.append(row) if add_geo_artefact is False: - cls.remove_geo_artefact_csv(reader=reader, new_file=new_file) - if add_attribute_info: - cls.add_attribute_info_csv(reader=reader, new_file=new_file, - temporary_path=temporary_path, path_to_subset=path_to_subset) + [header, data] = cls.remove_geo_artefact_csv(header=header, data=data) + #if add_attribute_info: + # cls.add_attribute_info_csv(reader=reader, new_file=new_file, + # temporary_path=temporary_path, path_to_subset=path_to_subset) + new_file.write(delimiter.join(header) + '\n') + for d in data: + new_file.write(delimiter.join(d) + '\n') new_file.close() @classmethod def add_attribute_info_csv(cls, reader, new_file, temporary_path, path_to_subset): converter = OtlmowConverter() - print('test') dotnotation_module = DotnotationHelper() instantiated_attributes = converter.create_assets_from_file(filepath=temporary_path, path_to_subset=path_to_subset) diff --git a/requirements.txt b/requirements.txt index ab21f4e..a5ef31e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ pluggy>=1.0.0 pytest>=6.2.5 pytest-cov>=4.0.0 pytest-subtests>=0.8.0 -openpyxl~=3.1.2 \ No newline at end of file +openpyxl~=3.1.2 +otlmow-model==2.9.1