Skip to content
Snippets Groups Projects
Commit db54ff43 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

wip

parent 3931c9bd
No related branches found
No related tags found
2 merge requests!100WIP: Filling XLSX: Seems to be working.,!93Filling XLSX: Everything except multiple choice.
Pipeline #48476 failed
...@@ -54,11 +54,10 @@ def _get_column_types(sheet: Worksheet) -> OrderedDict: ...@@ -54,11 +54,10 @@ def _get_column_types(sheet: Worksheet) -> OrderedDict:
type_row_index = _get_row_type_column_index(sheet) type_row_index = _get_row_type_column_index(sheet)
for idx, col in enumerate(sheet.columns): for idx, col in enumerate(sheet.columns):
type_cell = col[type_row_index] type_cell = col[type_row_index]
result[idx] = type_cell.value result[idx] = type_cell.value if type_cell.value is not None else ColumnType.IGNORE.name
assert (hasattr(ColumnType, type_cell.value) assert (hasattr(ColumnType, result[idx])
or type_cell.value == RowType.COL_TYPE.name or result[idx] == RowType.COL_TYPE.name), (
or type_cell.value is None), ( f"Unexpected column type value ({idx}{type_row_index}): {type_cell.value}")
f"Unexpected column type value: {type_cell.value}")
return result return result
...@@ -281,16 +280,17 @@ out: union[dict, None] ...@@ -281,16 +280,17 @@ out: union[dict, None]
next_context = context.next_level(name) next_context = context.next_level(name)
# preprocessing # preprocessing
if isinstance(content, list): if isinstance(content, list):
if not content: if not content: # empty list
continue continue
# Must be all of the same type. # list elements must be all of the same type.
assert len(set(type(entry) for entry in content)) == 1 assert len(set(type(entry) for entry in content)) == 1
if isinstance(content[0], dict):
if isinstance(content[0], dict): # all elements are dicts
# An array of objects: must go into exploded sheet # An array of objects: must go into exploded sheet
for entry in content: for entry in content:
self._handle_data(data=entry, current_path=path, context=next_context) self._handle_data(data=entry, current_path=path, context=next_context)
continue continue
elif isinstance(content, dict): elif isinstance(content, dict): # we recurse and simply use the result
if not current_path: # Special handling for top level if not current_path: # Special handling for top level
self._handle_data(content, current_path=path, context=next_context) self._handle_data(content, current_path=path, context=next_context)
continue continue
...@@ -301,26 +301,27 @@ out: union[dict, None] ...@@ -301,26 +301,27 @@ out: union[dict, None]
insertables.update(insert) insertables.update(insert)
continue continue
else: # scalars else: # scalars
content = [content] content = [content] # make list for unified treatment below
# collecting the data # collecting the data
assert isinstance(content, list) assert isinstance(content, list) # TODO do we want this??? make list non-lists?
if len(content) == 1: if len(content) == 1:
value = content[0] value = content[0]
else: else:
value = ";".join(content) value = ";".join(content) # TODO we need escaping of values
path_str = p2s(path) path_str = p2s(path)
assert path_str not in insertables assert path_str not in insertables
insertables[path_str] = value insertables[path_str] = value
if only_collect_insertables: if only_collect_insertables:
return insertables return insertables
if not current_path: if not current_path: # top level returns (?)
return None return None
# actual data insertion # actual data insertion
insert_row = None insert_row = None
sheet = None sheet = None
for path_str, value in insertables.items(): for path_str, value in insertables.items():
sheet_meta = self._sheet_index[path_str] sheet_meta = self._sheet_index[path_str]
if sheet is None: if sheet is None:
sheet = sheet_meta.sheet sheet = sheet_meta.sheet
......
...@@ -42,7 +42,7 @@ class ColumnType(Enum): ...@@ -42,7 +42,7 @@ class ColumnType(Enum):
SCALAR = 1 SCALAR = 1
LIST = 2 LIST = 2
FOREIGN = 3 FOREIGN = 3
IGNORE = 3 IGNORE = 4
class RowType(Enum): class RowType(Enum):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment