Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2223 mapping name importer source #214

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spine_items/importer/flattened_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -376,6 +380,8 @@ def display_position(self, row):
return component.value + 1
if component.position == Position.table_name:
return "<table name>"
if component.position == Position.mapping_name:
return "<mapping name>"
if component.position >= 0:
return component.position + 1
return -(component.position + 1) + 1
Expand Down
5 changes: 4 additions & 1 deletion spine_items/importer/mvcmodels/mappings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def _mapping_data(flattened_mappings, index, role):
display = flattened_mappings.display_position(index.row())
if display == "<table name>":
return flattened_mappings.mapping_list_item.source_table_item.name
elif display == "<mapping name>":
return flattened_mappings.mapping_list_item.name
return display
if column == FlattenedColumn.REGEXP:
return flattened_mappings.component_at(index.row()).filter_re
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion spine_items/importer/widgets/import_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/importer/mvcmodels/test_mappings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading