Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
4ef559b2
Commit
4ef559b2
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP for fill_xlsx: More graceful handling of incomplete data.
parent
a504c310
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!100
WIP: Filling XLSX: Seems to be working.
,
!93
Filling XLSX: Everything except multiple choice.
Pipeline
#48831
failed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+10
-3
10 additions, 3 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
with
10 additions
and
3 deletions
src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+
10
−
3
View file @
4ef559b2
...
...
@@ -27,6 +27,7 @@ import pathlib
from
collections
import
OrderedDict
from
types
import
SimpleNamespace
from
typing
import
Any
,
Dict
,
List
,
Optional
,
TextIO
,
Union
from
warnings
import
warn
from
jsonschema
import
FormatChecker
,
validate
from
jsonschema.exceptions
import
ValidationError
...
...
@@ -134,8 +135,9 @@ def _read_or_dict(data: Union[dict, str, TextIO]) -> dict:
class
TemplateFiller
:
"""
Class to fill XLSX templates. Has an index for all relevant columns.
"""
def
__init__
(
self
,
workbook
:
Workbook
):
def
__init__
(
self
,
workbook
:
Workbook
,
graceful
:
bool
=
False
):
self
.
_workbook
=
workbook
self
.
_graceful
=
graceful
self
.
_create_index
()
@property
...
...
@@ -305,6 +307,7 @@ out: union[dict, None]
# collecting the data
assert
isinstance
(
content
,
list
)
content
=
[
str
(
x
)
for
x
in
content
]
value
=
"
;
"
.
join
(
content
)
# TODO we need escaping of values
path_str
=
p2s
(
path
)
assert
path_str
not
in
insertables
...
...
@@ -318,6 +321,9 @@ out: union[dict, None]
insert_row
=
None
sheet
=
None
for
path_str
,
value
in
insertables
.
items
():
if
self
.
_graceful
and
path_str
not
in
self
.
_sheet_index
:
warn
(
f
"
Ignoring path with missing sheet index:
{
path_str
}
"
)
continue
sheet_meta
=
self
.
_sheet_index
[
path_str
]
if
sheet
is
None
:
sheet
=
sheet_meta
.
sheet
...
...
@@ -359,7 +365,8 @@ result: str
Path for the result XLSX.
validation_schema: dict, optional
If given, validate the date against this schema first. This raises an exception if the validation
fails.
fails. If no validation schema is given, try to ignore more errors in the data when filling the
XLSX template.
"""
data
=
_read_or_dict
(
data
)
assert
isinstance
(
data
,
dict
)
...
...
@@ -377,7 +384,7 @@ validation_schema: dict, optional
# Filling the data
result_wb
=
load_workbook
(
template
)
template_filler
=
TemplateFiller
(
result_wb
)
template_filler
=
TemplateFiller
(
result_wb
,
graceful
=
(
validation_schema
is
None
)
)
template_filler
.
fill_data
(
data
=
data
)
parentpath
=
pathlib
.
Path
(
result
).
parent
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment