Skip to content

Commit a508e31

Browse files
committed
Fix export_to_excel cli
Fix cls_name in entities.py
1 parent 7cf3729 commit a508e31

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

.vscode/settings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"cwd": "${workspaceFolder}",
5858
"program": "${workspaceFolder}/.venv/bin/bam_masterdata",
5959
"justMyCode": false,
60-
"args": ["export-entities-to-json"]
60+
"args": ["export_to_json"]
6161
},
6262
{
6363
"name": "BM export-to-excel",
@@ -66,7 +66,7 @@
6666
"cwd": "${workspaceFolder}",
6767
"program": "${workspaceFolder}/.venv/bin/bam_masterdata",
6868
"justMyCode": false,
69-
"args": ["export-entities-to-excel"]
69+
"args": ["export_to_excel"]
7070
},
7171
]
7272
},

bam_masterdata/cli/entities_to_excel.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def entities_to_excel(
4545
val = getattr(obj, f_set)
4646
row.append(val)
4747
worksheet.append(row)
48+
worksheet.append([""]) # empty row after entity definitions
4849
return None
4950

5051
# All other datamodel modules
@@ -69,8 +70,8 @@ def entities_to_excel(
6970
]
7071
worksheet.append(header_values)
7172

72-
# Properties assignment for ObjectType
73-
if obj_instance.cls_name == "ObjectType":
73+
# Properties assignment for ObjectType, DatasetType, and CollectionType
74+
if obj_instance.cls_name in ["ObjectType", "DatasetType", "CollectionType"]:
7475
if not obj_instance.properties:
7576
continue
7677
worksheet.append(obj_instance.properties[0].excel_headers)

bam_masterdata/datamodel/collection_types.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from bam_masterdata.metadata.definitions import CollectionTypeDef, PropertyTypeAssignment
1+
from bam_masterdata.metadata.definitions import (
2+
CollectionTypeDef,
3+
PropertyTypeAssignment,
4+
)
25
from bam_masterdata.metadata.entities import CollectionType
36

47

bam_masterdata/metadata/entities.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def to_dict(self) -> dict:
5555
@property
5656
def cls_name(self) -> str:
5757
"""
58-
Returns the entity name of the class as a string to speed up checks.
58+
Returns the entity name of the class as a string to speed up checks. This is a property
59+
to be overwritten by each of the abstract entity types.
5960
"""
6061
return self.__class__.__name__
6162

@@ -108,6 +109,13 @@ def model_validator_after_init(cls, data: Any) -> Any:
108109

109110
return data
110111

112+
@property
113+
def cls_name(self) -> str:
114+
"""
115+
Returns the entity name of the class as a string.
116+
"""
117+
return "ObjectType"
118+
111119

112120
class VocabularyType(BaseEntity):
113121
"""
@@ -147,10 +155,27 @@ def model_validator_after_init(cls, data: Any) -> Any:
147155

148156
return data
149157

158+
@property
159+
def cls_name(self) -> str:
160+
"""
161+
Returns the entity name of the class as a string.
162+
"""
163+
return "VocabularyType"
164+
150165

151166
class CollectionType(ObjectType):
152-
pass
167+
@property
168+
def cls_name(self) -> str:
169+
"""
170+
Returns the entity name of the class as a string.
171+
"""
172+
return "CollectionType"
153173

154174

155175
class DatasetType(ObjectType):
156-
pass
176+
@property
177+
def cls_name(self) -> str:
178+
"""
179+
Returns the entity name of the class as a string.
180+
"""
181+
return "DatasetType"

0 commit comments

Comments
 (0)