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
f76aaacf
Verified
Commit
f76aaacf
authored
10 months ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
FIX: Foreign key specification when generating XLSX templates.
parent
44e6a553
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!107
Release v0.11.0
,
!102
ENH: XLSX reader
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/table_json_conversion/table_generator.py
+20
-6
20 additions, 6 deletions
...aosadvancedtools/table_json_conversion/table_generator.py
unittests/table_json_conversion/test_table_template_generator.py
+1
-1
1 addition, 1 deletion
...ts/table_json_conversion/test_table_template_generator.py
with
21 additions
and
7 deletions
src/caosadvancedtools/table_json_conversion/table_generator.py
+
20
−
6
View file @
f76aaacf
...
...
@@ -71,6 +71,11 @@ class TableTemplateGenerator(ABC):
Example: ``{
"
Training
"
: {
"
__this__
"
: [
"
date
"
],
"
Person
"
: [
"
name
"
,
"
email
"
]}}``
Here, ``date`` is the sole foreign key for Training.
| It probably is worth extending the first example, with a case where a
"
Training
"
shall
be distiguished by the
"
name
"
and
"
email
"
of a
"
Person
"
which it references. The
foreign keys for this example are specified like this:
| ``{
"
Training
"
: {
"
__this__
"
: [[
"
Person
"
,
"
name
"
], [
"
Person
"
,
"
email
"
]]}}``
"""
def
_generate_sheets_from_schema
(
self
,
schema
:
dict
,
foreign_keys
:
Optional
[
dict
]
=
None
...
...
@@ -121,7 +126,13 @@ class TableTemplateGenerator(ABC):
return
sheets
def
_get_foreign_keys
(
self
,
keys
:
dict
,
path
:
list
)
->
list
:
"""
Return the foreign keys that are needed at the location to which path points.
"""
"""
Return the foreign keys that are needed at the location to which path points.
Returns
-------
foreign_keys: list
Contains strings or lists of strings.
"""
msg
=
f
"
A foreign key definition is missing for path:
\n
{
path
}
\n
Keys are:
\n
{
keys
}
"
while
path
:
if
keys
is
None
or
path
[
0
]
not
in
keys
:
...
...
@@ -198,14 +209,17 @@ class TableTemplateGenerator(ABC):
"
string was given:
\n
"
f
"
{
array_path
}
->
{
foreigns
}
"
)
for
foreign
in
foreigns
:
internal_key
=
p2s
(
array_path
+
[
foreign
])
if
isinstance
(
foreign
,
str
):
foreign
=
[
foreign
]
internal_key
=
p2s
(
array_path
+
foreign
)
if
internal_key
in
sheets
[
sheetname
]:
raise
ValueError
(
"
The schema would lead to two columns with the
same
"
"
name, which is forbidden:
\n
"
raise
ValueError
(
"
The schema would lead to two columns with the
"
"
same
name, which is forbidden:
\n
"
f
"
{
foreign
}
->
{
internal_key
}
"
)
ref_sheet
=
p2s
(
array_path
)
sheets
[
sheetname
][
internal_key
]
=
(
ColumnType
.
FOREIGN
,
f
"
see sheet
'
{
ref_sheet
}
'"
,
array_path
+
[
foreign
])
ColumnType
.
FOREIGN
,
f
"
see sheet
'
{
ref_sheet
}
'"
,
array_path
+
foreign
)
# Columns are added to the new sheet, thus we do not return any columns for the
# current sheet.
return
{}
...
...
@@ -301,7 +315,7 @@ class XLSXTemplateGenerator(TableTemplateGenerator):
definition dict
You need to pass the dict of a single sheet to this function.
"""
return
max
(
[
len
(
path
)
for
_
,
_
,
path
in
sheetdef
.
values
()
]
)
return
max
(
len
(
path
)
for
_
,
_
,
path
in
sheetdef
.
values
())
@staticmethod
def
_get_ordered_cols
(
sheetdef
:
dict
)
->
list
:
...
...
This diff is collapsed.
Click to expand it.
unittests/table_json_conversion/test_table_template_generator.py
+
1
−
1
View file @
f76aaacf
...
...
@@ -263,7 +263,7 @@ def test_model_with_indirect_reference():
_compare_generated_to_known_good
(
schema_file
=
rfp
(
"
data/indirect_schema.json
"
),
known_good
=
rfp
(
"
data/indirect_template.xlsx
"
),
foreign_keys
=
{
"
Wrapper
"
:
[
"
Training
.
name
"
,
"
Training
.
url
"
]},
foreign_keys
=
{
"
Wrapper
"
:
{
"
__this__
"
:
[
[
"
Training
"
,
"
name
"
]
,
[
"
Training
"
,
"
url
"
]
]}
},
outfile
=
None
)
...
...
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