(core) Add RenameChoices user action

Summary:
["RenameChoices", table_id, col_id, renames]
Updates the data in a Choice/ChoiceList column to reflect the new choice names.
`renames` should be a dict of `{old_choice_name: new_choice_name}`.
This doesn't touch the choices configuration in widgetOptions, that must be done separately.
Frontend to be done in another diff.

Test Plan: Added two Python unit tests.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3050
This commit is contained in:
Alex Hall
2021-09-30 14:14:52 +02:00
parent 02fd71d9bb
commit d4ea5b3761
5 changed files with 184 additions and 2 deletions

View File

@@ -225,6 +225,20 @@ class BaseColumn(object):
# pylint: disable=no-self-use, unused-argument
return values, []
def rename_choices(self, renames):
row_ids = []
values = []
for row_id, value in enumerate(self._data):
if value is not None and self.type_obj.is_right_type(value):
value = self._rename_cell_choice(renames, value)
if value is not None:
row_ids.append(row_id)
values.append(value)
return row_ids, values
def _rename_cell_choice(self, renames, value):
return renames.get(value, value)
class DataColumn(BaseColumn):
"""
@@ -361,6 +375,9 @@ class ChoiceListColumn(BaseColumn):
def _make_rich_value(self, typed_value):
return () if typed_value is None else typed_value
def _rename_cell_choice(self, renames, value):
return tuple(renames.get(choice, choice) for choice in value)
class BaseReferenceColumn(BaseColumn):
"""