From 2946d7b6206831b466fb34633683ddb955052eb4 Mon Sep 17 00:00:00 2001 From: Henrik Koski Date: Thu, 27 Jun 2024 10:39:45 +0300 Subject: [PATCH 1/3] Add mapping name as mapping source in importer It is now possible to map the active mapping name to the source ref. Re spine-tools/Spine-Toolbox#2223 --- spine_items/importer/flattened_mappings.py | 6 ++++++ spine_items/importer/mvcmodels/mappings_model.py | 5 ++++- spine_items/importer/widgets/import_mappings.py | 2 +- tests/importer/mvcmodels/test_mappings_model.py | 6 +++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spine_items/importer/flattened_mappings.py b/spine_items/importer/flattened_mappings.py index e67fd877..409c0c8c 100644 --- a/spine_items/importer/flattened_mappings.py +++ b/spine_items/importer/flattened_mappings.py @@ -308,6 +308,8 @@ def display_position_type(self, row): return "Column Header" if component.position == Position.table_name: return "Table Name" + if component.position == Position.mapping_name: + return "Mapping Name" if component.position >= 0: return "Column" return "Row" @@ -343,6 +345,8 @@ def set_display_position_type(self, row, position_type): component.value = None elif position_type == "Table Name": component.position = Position.table_name + elif position_type == "Mapping Name": + component.position = Position.mapping_name self._row_issues = None def display_position(self, row): @@ -376,6 +380,8 @@ def display_position(self, row): return component.value + 1 if component.position == Position.table_name: return "" + if component.position == Position.mapping_name: + return "" if component.position >= 0: return component.position + 1 return -(component.position + 1) + 1 diff --git a/spine_items/importer/mvcmodels/mappings_model.py b/spine_items/importer/mvcmodels/mappings_model.py index 7bf990f7..237a3ae5 100644 --- a/spine_items/importer/mvcmodels/mappings_model.py +++ b/spine_items/importer/mvcmodels/mappings_model.py @@ -320,6 +320,8 @@ def _mapping_data(flattened_mappings, index, role): display = flattened_mappings.display_position(index.row()) if display == "
": return flattened_mappings.mapping_list_item.source_table_item.name + elif display == "": + return flattened_mappings.mapping_list_item.name return display if column == FlattenedColumn.REGEXP: return flattened_mappings.component_at(index.row()).filter_re @@ -1403,7 +1405,8 @@ def polish_mapping(list_index, header): """ mapping_list_item = list_index.internalPointer() table_name = mapping_list_item.source_table_item.name - mapping_list_item.flattened_mappings.root_mapping.polish(table_name, header, for_preview=True) + mapping_name = mapping_list_item.name + mapping_list_item.flattened_mappings.root_mapping.polish(table_name, header, mapping_name, for_preview=True) # We don't emit dataChanged here as polishing is just beautification and # it would mess up the undo system which relies on real changes. diff --git a/spine_items/importer/widgets/import_mappings.py b/spine_items/importer/widgets/import_mappings.py index 604f158a..4bb77264 100644 --- a/spine_items/importer/widgets/import_mappings.py +++ b/spine_items/importer/widgets/import_mappings.py @@ -23,7 +23,7 @@ from ..mvcmodels.mappings_model import FlattenedColumn from ...widgets import combo_box_width -SOURCE_TYPES = ("Constant", "Column", "Row", "Column Header", "Headers", "Table Name", "None") +SOURCE_TYPES = ("Constant", "Column", "Row", "Column Header", "Headers", "Table Name", "Mapping Name", "None") class ImportMappings: diff --git a/tests/importer/mvcmodels/test_mappings_model.py b/tests/importer/mvcmodels/test_mappings_model.py index a56cac54..45df2263 100644 --- a/tests/importer/mvcmodels/test_mappings_model.py +++ b/tests/importer/mvcmodels/test_mappings_model.py @@ -774,7 +774,7 @@ def test_data_when_mapping_valid_object_class_with_parameters(self): mapping = import_mapping_from_dict(mapping_dict) table_name = "source table" header = ["1", "2", "3", "4", "fifth column"] - mapping.polish(table_name, header) + mapping.polish(table_name, header, "") self._model.set_root_mapping(self._table_index.row(), self._list_index.row(), mapping) self.assertEqual(self._model.rowCount(self._list_index), 9) self.assertEqual(self._model.columnCount(self._list_index), 4) @@ -873,7 +873,7 @@ def test_data_when_valid_object_class_with_nested_map(self): mapping = import_mapping_from_dict(mapping_dict) table_name = "source table" header = ["1", "2", "3", "4", "fifth column", "sixth column"] - mapping.polish(table_name, header) + mapping.polish(table_name, header, "") self._model.set_root_mapping(self._table_index.row(), self._list_index.row(), mapping) self.assertEqual(self._model.rowCount(self._list_index), 11) self.assertEqual(self._model.columnCount(self._list_index), 4) @@ -1062,7 +1062,7 @@ def test_data_when_mapping_multidimensional_relationship_class_with_parameters(s mapping = import_mapping_from_dict(mapping_dict) table_name = "source table" header = ["column header", "2", "3", "4", "fifth column", "sixth column"] - mapping.polish(table_name, header) + mapping.polish(table_name, header, "") self._model.set_root_mapping(self._table_index.row(), self._list_index.row(), mapping) self.assertEqual(self._model.rowCount(self._list_index), 12) self.assertEqual(self._model.columnCount(self._list_index), 4) From 64c91d3d78bab48308ff6fe3bcf18fa008e09f2f Mon Sep 17 00:00:00 2001 From: Henrik Koski Date: Thu, 27 Jun 2024 10:42:57 +0300 Subject: [PATCH 2/3] Change requirements for tests Re spine-tools/Spine-Toolbox#2223 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 51082f94..eb56ff37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e git+https://github.com/spine-tools/Spine-Database-API.git#egg=spinedb_api +-e git+https://github.com/spine-tools/Spine-Database-API.git@issue_2223_mapping_name_importer_source#egg=spinedb_api -e git+https://github.com/spine-tools/spine-engine.git#egg=spine_engine -e git+https://github.com/spine-tools/Spine-Toolbox.git#egg=spinetoolbox -e . From a867b89d77f68e3e6c3021cc4d3dcbdce3af38ea Mon Sep 17 00:00:00 2001 From: Henrik Koski Date: Thu, 27 Jun 2024 11:02:51 +0300 Subject: [PATCH 3/3] Back to default requirements Re spine-tools/Spine-Toolbox#2223 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index eb56ff37..51082f94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ --e git+https://github.com/spine-tools/Spine-Database-API.git@issue_2223_mapping_name_importer_source#egg=spinedb_api +-e git+https://github.com/spine-tools/Spine-Database-API.git#egg=spinedb_api -e git+https://github.com/spine-tools/spine-engine.git#egg=spine_engine -e git+https://github.com/spine-tools/Spine-Toolbox.git#egg=spinetoolbox -e .