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
ceff40d2
Commit
ceff40d2
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
FIX: no explode for top level; clean title string
parent
8b2db58d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!100
WIP: Filling XLSX: Seems to be working.
,
!94
ENH: add framework for converting json schema into table templates
,
!93
Filling XLSX: Everything except multiple choice.
,
!92
ENH: xlsx template generator
Pipeline
#47854
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/table_generator.py
+9
-8
9 additions, 8 deletions
...aosadvancedtools/table_json_conversion/table_generator.py
with
9 additions
and
8 deletions
src/caosadvancedtools/table_json_conversion/table_generator.py
+
9
−
8
View file @
ceff40d2
...
...
@@ -22,8 +22,8 @@
"""
This module allows to generate template tables from JSON schemas.
"""
import
argparse
import
re
import
sys
from
abc
import
ABC
,
abstractmethod
from
argparse
import
RawTextHelpFormatter
...
...
@@ -31,6 +31,7 @@ from enum import Enum
from
typing
import
Union
from
openpyxl
import
Workbook
from
openpyxl.workbook.child
import
INVALID_TITLE_REGEX
class
ColumnType
(
Enum
):
...
...
@@ -113,23 +114,23 @@ class TableTemplateGenerator(ABC):
def
_get_foreign_keys
(
self
,
foreign_keys
:
dict
,
path
:
list
)
->
list
:
"""
returns the foreign keys that are needed at the location to which path points
"""
path
=
list
(
path
)
c
path
=
list
(
path
)
keys
=
foreign_keys
selected_keys
=
None
while
path
:
while
c
path
:
if
keys
is
None
:
raise
ValueError
(
f
"
A foreign key definition is missing for path:
"
f
"
\n
{
path
}
\n
{
foreign_keys
}
"
)
if
path
[
0
]
not
in
keys
:
if
c
path
[
0
]
not
in
keys
:
raise
ValueError
(
f
"
A foreign key definition is missing for path:
\n
{
path
}
\n
{
keys
}
"
)
keys
=
keys
[
path
[
0
]]
keys
=
keys
[
c
path
[
0
]]
if
isinstance
(
keys
,
tuple
):
selected_keys
,
keys
=
keys
elif
isinstance
(
keys
,
list
):
selected_keys
,
keys
=
keys
,
None
else
:
selected_keys
,
keys
=
None
,
keys
path
=
path
[
1
:]
c
path
=
c
path
[
1
:]
if
selected_keys
is
None
:
raise
ValueError
(
f
"
A foreign key definition is missing for path:
"
f
"
\n
{
path
}
\n
{
foreign_keys
}
"
)
...
...
@@ -147,7 +148,7 @@ class TableTemplateGenerator(ABC):
# if it is an array, value defs are in 'items'
if
'
type
'
in
schema
and
schema
[
'
type
'
]
==
'
array
'
:
if
'
type
'
in
schema
[
'
items
'
]
and
schema
[
'
items
'
][
'
type
'
]
==
'
object
'
:
# list of references; special treatment
if
'
type
'
in
schema
[
'
items
'
]
and
schema
[
'
items
'
][
'
type
'
]
==
'
object
'
and
len
(
path
)
>
1
:
# list of references; special treatment
# we add a new sheet
sheets
[
"
.
"
.
join
(
path
)]
=
self
.
_treat_schema_element
(
schema
[
'
items
'
],
sheets
,
path
,
foreign_keys
)
for
c
in
self
.
_get_foreign_keys
(
foreign_keys
,
path
[:
-
1
]):
...
...
@@ -245,7 +246,7 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
wb
=
Workbook
()
assert
wb
.
sheetnames
==
[
"
Sheet
"
]
for
sn
,
sheetdef
in
sheets
.
items
():
ws
=
wb
.
create_sheet
(
sn
)
ws
=
wb
.
create_sheet
(
re
.
sub
(
INVALID_TITLE_REGEX
,
'
_
'
,
sn
)
)
# first row will by the COL_TYPE row
# first column will be the indicator row with values COL_TYPE, PATH, IGNORE
# the COL_TYPE row will be followed by as many PATH rows as needed
...
...
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