(core) New type conversion in the backend

Summary: This is https://phab.getgrist.com/D3205 plus some changes (https://github.com/dsagal/grist/compare/type-convert...type-convert-server?expand=1) that move the conversion process to the backend. A new user action ConvertFromColumn uses `call_external` so that the data engine can delegate back to ActiveDoc. Code for creating formatters and parsers is significantly refactored so that most of the logic is in `common` and can be used in different ways.

Test Plan: The original diff adds plenty of tests.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3240
This commit is contained in:
Alex Hall
2022-02-04 13:13:03 +02:00
parent 4890a1fe89
commit 5d671bf0b3
25 changed files with 593 additions and 492 deletions

View File

@@ -1037,7 +1037,13 @@ class UserActions(object):
if not clean_colinfo["isFormula"]:
raise ValueError("AddColumn: cannot add a non-formula column to a summary table")
transform = col_id is not None and col_id.startswith('gristHelper_Transform')
transform = (
col_id is not None and
col_id.startswith((
'gristHelper_Transform',
'gristHelper_Converted',
))
)
if transform:
# Delete any currently existing transform columns with the same id
@@ -1256,6 +1262,29 @@ class UserActions(object):
finally:
self._engine.out_actions.undo.append(mod_action)
@useraction
def ConvertFromColumn(self, table_id, src_col_id, dst_col_id, typ, widgetOptions, visibleColRef):
from sandbox import call_external
table = self._engine.tables[table_id]
src_col = self._docmodel.get_column_rec(table_id, src_col_id)
src_column = table.get_column(src_col_id)
row_ids = list(table.row_ids)
src_values = [encode_object(src_column.raw_get(r)) for r in row_ids]
display_values = None
if src_col.displayCol:
display_col = table.get_column(src_col.displayCol.colId)
display_values = [encode_object(display_col.raw_get(r)) for r in row_ids]
converted_values = call_external(
"convertFromColumn",
src_col.id,
typ,
widgetOptions,
visibleColRef,
src_values,
display_values,
)
self.ModifyColumn(table_id, dst_col_id, {"type": typ})
self.BulkUpdateRecord(table_id, row_ids, {dst_col_id: converted_values})
@useraction
def CopyFromColumn(self, table_id, src_col_id, dst_col_id, widgetOptions):