mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user