Changeset fd1913f in flexoentity


Ignore:
Timestamp:
11/20/25 12:01:11 (8 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
9592936
Parents:
32fdc4a
Message:

version logic simplified - parsed renamed to to_dict

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • flexoentity/domain.py

    r32fdc4a rfd1913f  
    2222                                  fullname="Generic Domain", classification="UNCLASSIFIED")
    2323
    24     def __post_init__(self):
    25         super().__post_init__()
    26         # Create a FlexOID only if none was restored
    27         if not getattr(self, "flexo_id", None):
    28             self.flexo_id = FlexOID.safe_generate(
    29                 domain_id=self.domain_id,
    30                 entity_type=self.ENTITY_TYPE.value,   # "D"
    31                 state=EntityState.DRAFT.value,       # "D"
    32                 text=self.domain_id,                       # seed must be stable
    33                 version=1,
    34             )
    35 
    3624    @property
    3725    def text_seed(self) -> str:
     
    5644        flexo_id = FlexOID(data["flexo_id"])
    5745
    58         print("Data:", data)
    5946        obj = cls(
    6047            fullname=data.get("fullname", ""),
  • flexoentity/flexo_entity.py

    r32fdc4a rfd1913f  
    320320
    321321    @classmethod
    322     def from_json(cls, data_str: str) -> "FlexoEntity":
     322    def from_json(cls, data_str: str):
    323323        """I create a new instance from a JSON string."""
    324324        data = json.loads(data_str)
    325325        return cls.from_dict(data)
    326326
    327     @staticmethod
    328     def should_version(state) -> bool:
    329         """
    330         FIXME: This is now superfluous, because lifecycle changes should not increment
    331         version at all.
    332         I determine if a given lifecycle state should trigger a version increment.
    333 
    334         Entities typically version when they move into more stable or
    335         externally visible states, such as APPROVED, SIGNED, or PUBLISHED.
    336         """
    337 
    338         return state in (
    339             EntityState.APPROVED,
    340             EntityState.APPROVED_AND_SIGNED,
    341             EntityState.PUBLISHED,
    342         )
    343 
    344327    def _compute_fingerprint(self) -> str:
    345         """I always recompute the entity's content fingerprint."""
     328        """I recompute the entity's content fingerprint."""
    346329        seed = self.canonical_seed()
    347330        return hashlib.blake2s(seed.encode("utf-8"), digest_size=8).hexdigest().upper()
     
    349332    def _update_fingerprint(self) -> bool:
    350333        """
    351         FIXME: I am not sure if this is correct behaviour.
    352         I Update FlexOID if the content fingerprint changed.
     334        I update FlexOID if the content fingerprint changed.
    353335        """
    354336        new_fp = self._compute_fingerprint()
     
    379361            self.flexo_id = self.flexo_id.with_state(EntityState.OBSOLETE.value)
    380362            return
    381 
    382         # version bump only for stable/external states
    383         if self.should_version(target_state):
    384             self._update_fingerprint()
    385             self.flexo_id = FlexOID.next_version(self.flexo_id)
    386363
    387364        self.state = target_state
  • flexoentity/id_factory.py

    r32fdc4a rfd1913f  
    354354        return FlexOID.safe_generate(domain, entity_type, state, text, version=1)
    355355
    356     def parsed(self) -> dict:
     356    def to_dict(self) -> dict:
    357357        """
    358358        I answer a dictionary that describes all my components —
  • tests/conftest.py

    r32fdc4a rfd1913f  
    8282        # restore FlexoEntity core fields
    8383        if "flexo_id" in data:
    84             obj.flexo_id = FlexOID.parsed(data["flexo_id"])
     84            obj.flexo_id = FlexOID.to_dict(data["flexo_id"])
    8585        return obj
    8686
  • tests/test_flexoid.py

    r32fdc4a rfd1913f  
    134134def test_parsed_returns_expected_dict():
    135135    fid = FlexOID("GEN-I251101-ABCDEF123456@007S")
    136     data = fid.parsed()
     136    data = fid.to_dict()
    137137    assert data["domain_id"] == "GEN"
    138138    assert data["entity_type"] == "I"
Note: See TracChangeset for help on using the changeset viewer.