Skip to content
Snippets Groups Projects
Commit a504c310 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP for fill_xlsx.

parent db54ff43
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 #48828 failed
...@@ -282,7 +282,7 @@ out: union[dict, None] ...@@ -282,7 +282,7 @@ out: union[dict, None]
if isinstance(content, list): if isinstance(content, list):
if not content: # empty list if not content: # empty list
continue continue
# list elements 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): # all elements are dicts if isinstance(content[0], dict): # all elements are dicts
...@@ -304,24 +304,20 @@ out: union[dict, None] ...@@ -304,24 +304,20 @@ out: union[dict, None]
content = [content] # make list for unified treatment below content = [content] # make list for unified treatment below
# collecting the data # collecting the data
assert isinstance(content, list) # TODO do we want this??? make list non-lists? assert isinstance(content, list)
if len(content) == 1: value = ";".join(content) # TODO we need escaping of values
value = content[0]
else:
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: # top level returns (?) if not current_path: # Top level returns, because there are only sheets for the children.
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
...@@ -376,6 +372,8 @@ validation_schema: dict, optional ...@@ -376,6 +372,8 @@ validation_schema: dict, optional
except ValidationError as ve: except ValidationError as ve:
print(ve.message) print(ve.message)
raise RuntimeError("Validation failed") raise RuntimeError("Validation failed")
else:
print("No validation schema given, continue at your own risk.")
# Filling the data # Filling the data
result_wb = load_workbook(template) result_wb = load_workbook(template)
......
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