From efbcfda1003503c8c29946c31216147590c0e908 Mon Sep 17 00:00:00 2001 From: Tim Cowlishaw Date: Tue, 26 Sep 2023 14:50:00 +0200 Subject: [PATCH] Expose how the latest version came into being. a new `document.get_latest_manifestation_type` method which returns either "tna-enrich" or "transform" depending on the "name" property of the most recent manifestation date. This is used in the versions table in the editor UI to annotate each version with it's 'version type', which helps editors better understand where each version came from. --- src/caselawclient/models/documents.py | 10 ++++++++++ tests/models/test_documents.py | 1 + 2 files changed, 11 insertions(+) diff --git a/src/caselawclient/models/documents.py b/src/caselawclient/models/documents.py index 5d0a7183..e57824e3 100644 --- a/src/caselawclient/models/documents.py +++ b/src/caselawclient/models/documents.py @@ -216,6 +216,16 @@ def get_latest_manifestation_datetime( else: return max(events) + def get_latest_manifestation_type(self) -> Optional[str]: + return max( + ( + (type, time) + for type in ["transform", "tna-enriched"] + if (time := self.get_latest_manifestation_datetime(type)) + ), + key=lambda x: x[1], + )[0] + @cached_property def transformation_datetime(self) -> Optional[datetime.datetime]: return self.get_latest_manifestation_datetime("transform") diff --git a/tests/models/test_documents.py b/tests/models/test_documents.py index f096015d..d113b1f8 100644 --- a/tests/models/test_documents.py +++ b/tests/models/test_documents.py @@ -575,6 +575,7 @@ def test_dates(self, mock_api_client): assert document.enrichment_datetime.year == 2024 assert document.transformation_datetime.year == 2026 assert document.get_latest_manifestation_datetime().year == 2026 + assert document.get_latest_manifestation_type() == "transform" assert [ x.year for x in document.get_manifestation_datetimes("tna-enriched") ] == [2024, 2023]