Skip to content

Commit e22b0e4

Browse files
committed
Applying template for Entity.name & Introducing Meta.uuid
1 parent 1b2bf1f commit e22b0e4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/osw/model/entity.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydantic.v1 import Field, constr
1111

1212
from osw.model.static import OswBaseModel
13+
from osw.utils.strings import pascal_case
1314

1415

1516
class ReadAccess(OswBaseModel):
@@ -47,7 +48,7 @@ class WikiPage(OswBaseModel):
4748

4849

4950
class Meta(OswBaseModel):
50-
uuid: UUID = Field(default_factory=uuid4, title="UUID") # todo: code generator?
51+
uuid: UUID = Field(default_factory=uuid4, title="UUID")
5152
wiki_page: Optional[WikiPage] = Field(None, title="Wiki page")
5253
"""
5354
The wiki page containing this entity
@@ -101,6 +102,19 @@ class Entity(OswBaseModel):
101102
attachments: Optional[List[str]] = Field(None, title="File attachments")
102103
meta: Optional[Meta] = None
103104

105+
def __init__(self, **data):
106+
if data.get("label"):
107+
labels = []
108+
for label in data["label"]:
109+
if isinstance(label, dict):
110+
data["label"] = labels.append(Label(**label))
111+
else:
112+
labels.append(Label(text=label))
113+
data["label"] = labels
114+
if data.get("name") is None and "label" in data:
115+
data["name"] = pascal_case(data["label"][0].text)
116+
super().__init__(**data)
117+
104118

105119
class ObjectStatement(OswBaseModel):
106120
rdf_type: Optional[Any] = "rdf:Statement"

0 commit comments

Comments
 (0)