Skip to content

Commit

Permalink
Merge pull request #402 from nationalarchives/feature/expose-latest-m…
Browse files Browse the repository at this point in the history
…anifestation-type

Expose how the latest version came into being
  • Loading branch information
timcowlishaw authored Sep 29, 2023
2 parents b741800 + efbcfda commit 27b6e33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/caselawclient/models/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tests/models/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 27b6e33

Please sign in to comment.