Changeset ef964d8 in flexoentity for flexoentity/domain.py


Ignore:
Timestamp:
11/27/25 18:12:23 (7 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
4e11d58
Parents:
9a50e0b
Message:

new serialization structure adopted and tests fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • flexoentity/domain.py

    r9a50e0b ref964d8  
    1 from uuid import UUID
    21from dataclasses import dataclass
    3 from flexoentity import FlexOID, FlexoEntity, EntityType
     2from flexoentity import FlexoEntity, EntityType
     3
    44
    55@dataclass
     
    2626        return self.domain_id
    2727
     28    def _deserialize_content(self, content: dict):
     29        self.fullname = content.get("fullname", "")
     30        self.description = content.get("description", "")
     31        self.classification = content.get("classification", "UNCLASSIFIED")
     32
    2833    def _serialize_content(self):
    2934        return {
     
    3237            "classification": self.classification,
    3338        }
    34    
     39
    3540    @classmethod
    3641    def from_dict(cls, data):
    37         # Must have flexo_id
    38         if "flexo_id" not in data:
    39             raise ValueError("Domain serialization missing 'flexo_id'.")
    4042
    41         flexo_id = FlexOID(data["flexo_id"])
    42 
    43         obj = cls(
    44             fullname=data.get("fullname", ""),
    45             description=data.get("description", ""),
    46             classification=data.get("classification", "UNCLASSIFIED"),
    47             flexo_id=flexo_id,
    48             _in_factory=True
    49         )
    50 
    51         # Restore metadata
    52         obj.origin = data.get("origin")
    53         obj.fingerprint = data.get("fingerprint", "")
    54         obj.originator_id = (
    55             UUID(data["originator_id"]) if data.get("originator_id") else None
    56         )
    57         obj.owner_id = (
    58             UUID(data["owner_id"]) if data.get("owner_id") else None
    59         )
    60 
     43        obj = super().from_dict(data)
     44        content = data.get("content", {})
     45        obj._deserialize_content(content)
    6146        return obj
Note: See TracChangeset for help on using the changeset viewer.