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:
type_row_index = _get_row_type_column_index(sheet)
for idx, col in enumerate(sheet.columns):
type_cell = col[type_row_index]
result[idx] = type_cell.value
assert (hasattr(ColumnType, type_cell.value)
or type_cell.value == RowType.COL_TYPE.name
or type_cell.value is None), (
f"Unexpected column type value: {type_cell.value}")
result[idx] = type_cell.value if type_cell.value is not None else ColumnType.IGNORE.name
assert (hasattr(ColumnType, result[idx])
or result[idx] == RowType.COL_TYPE.name), (
f"Unexpected column type value ({idx}{type_row_index}): {type_cell.value}")
return result
......@@ -281,16 +280,17 @@ out: union[dict, None]
next_context = context.next_level(name)
# preprocessing
if isinstance(content, list):
if not content:
if not content: # empty list
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
if isinstance(content[0], dict):
if isinstance(content[0], dict): # all elements are dicts
# An array of objects: must go into exploded sheet
for entry in content:
self._handle_data(data=entry, current_path=path, context=next_context)
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
self._handle_data(content, current_path=path, context=next_context)
continue
......@@ -301,26 +301,27 @@ out: union[dict, None]
insertables.update(insert)
continue
else: # scalars
content = [content]
content = [content] # make list for unified treatment below
# collecting the data
assert isinstance(content, list)
assert isinstance(content, list) # TODO do we want this??? make list non-lists?
if len(content) == 1:
value = content[0]
else:
value = ";".join(content)
value = ";".join(content) # TODO we need escaping of values
path_str = p2s(path)
assert path_str not in insertables
insertables[path_str] = value
if only_collect_insertables:
return insertables
if not current_path:
if not current_path: # top level returns (?)
return None
# actual data insertion
insert_row = None
sheet = None
for path_str, value in insertables.items():
sheet_meta = self._sheet_index[path_str]
if sheet is None:
sheet = sheet_meta.sheet
......
......@@ -42,7 +42,7 @@ class ColumnType(Enum):
SCALAR = 1
LIST = 2
FOREIGN = 3
IGNORE = 3
IGNORE = 4
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