|  | 
| 10 | 10 | from pydantic.v1 import Field, constr | 
| 11 | 11 | 
 | 
| 12 | 12 | from osw.model.static import OswBaseModel | 
|  | 13 | +from osw.utils.strings import pascal_case | 
| 13 | 14 | 
 | 
| 14 | 15 | 
 | 
| 15 | 16 | class ReadAccess(OswBaseModel): | 
| @@ -47,7 +48,7 @@ class WikiPage(OswBaseModel): | 
| 47 | 48 | 
 | 
| 48 | 49 | 
 | 
| 49 | 50 | class Meta(OswBaseModel): | 
| 50 |  | -    uuid: UUID = Field(default_factory=uuid4, title="UUID")  # todo: code generator? | 
|  | 51 | +    uuid: UUID = Field(default_factory=uuid4, title="UUID") | 
| 51 | 52 |     wiki_page: Optional[WikiPage] = Field(None, title="Wiki page") | 
| 52 | 53 |     """ | 
| 53 | 54 |     The wiki page containing this entity | 
| @@ -101,6 +102,19 @@ class Entity(OswBaseModel): | 
| 101 | 102 |     attachments: Optional[List[str]] = Field(None, title="File attachments") | 
| 102 | 103 |     meta: Optional[Meta] = None | 
| 103 | 104 | 
 | 
|  | 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 | + | 
| 104 | 118 | 
 | 
| 105 | 119 | class ObjectStatement(OswBaseModel): | 
| 106 | 120 |     rdf_type: Optional[Any] = "rdf:Statement" | 
|  | 
0 commit comments