Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Jan 24, 2025
1 parent 63ac3f2 commit 2f3013e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/caselawclient/models/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
NotSupportedOnVersion,
OnlySupportedOnVersion,
)

from caselawclient.identifier_resolution import IdentifierResolutions
from caselawclient.models.identifiers import Identifier
from caselawclient.models.identifiers.fclid import FindCaseLawIdentifier, FindCaseLawIdentifierSchema
from caselawclient.models.identifiers.unpacker import unpack_all_identifiers_from_etree
Expand Down Expand Up @@ -551,3 +553,17 @@ def __getattr__(self, name: str) -> Any:
return getattr(self.body, name)
except Exception:
raise AttributeError(f"Neither 'Document' nor 'DocumentBody' objects have an attribute '{name}'")

def linked_document_resolutions(self, namespaces: list[str], only_published=True) -> IdentifierResolutions:
"""Get documents which share the same neutral citation as this document."""
if not hasattr(self, "neutral_citation") or not self.neutral_citation:
return []
all_similar_resolutions = self.api_client.resolve_from_identifier_value(self.neutral_citation).
if only_published:
valid_resolutions = all_similar_resolutions.published()
else:
valid_resolutions = all_similar_resolutions
# only documents which aren't this one and have a right namespace
filtered_resolutions = [resolution for resolution in valid_resolutions if
resolution.identifier_slug != self.uri and resolution.identifier_namespace in namespaces]
return filtered_resolutions
7 changes: 7 additions & 0 deletions src/caselawclient/models/judgments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from caselawclient.models.press_summaries import PressSummary

from .documents import Document, DocumentURIString
from caselawclient.identifier_resolution import IdentifierResolutions


class Judgment(NeutralCitationMixin, Document):
Expand Down Expand Up @@ -49,3 +50,9 @@ def linked_document(self) -> Optional["PressSummary"]:
return PressSummary(uri, self.api_client)
except DocumentNotFoundError:
return None

@cached_property
def linked_press_summaries(self, only_published=True):
return self.linked_document_resolutions(["uksummaryofncn"], only_published)


4 changes: 4 additions & 0 deletions src/caselawclient/models/press_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ def linked_document(self) -> Optional[Judgment]:
return Judgment(uri, self.api_client)
except DocumentNotFoundError:
return None

def linked_judgments(self, only_published=True):
return self.linked_document_resolutions(["ukncn"], only_published)

0 comments on commit 2f3013e

Please sign in to comment.