caselawclient.models.neutral_citation_mixin
1from abc import ABC, abstractmethod 2from functools import cached_property 3from typing import Any, Optional 4 5from ds_caselaw_utils import neutral_url 6from ds_caselaw_utils.types import NeutralCitationString 7from typing_extensions import deprecated 8 9 10class NeutralCitationMixin(ABC): 11 """ 12 A mixin class that provides functionality related to neutral citation. 13 14 The NeutralCitationMixin is intended to be used as a mixin in classes that represent legal documents 15 and need to handle neutral citation attributes and validation. 16 17 Notes: 18 - The document_noun attribute should be set in the child class that uses this mixin to provide 19 context-specific document noun strings for error messages and validation checks. 20 - The neutral_citation() method must be implemented in the child class to return the actual 21 neutral citation string for the legal document. 22 """ 23 24 def __init__(self, document_noun: str, *args: Any, **kwargs: Any) -> None: 25 self.attributes_to_validate: list[tuple[str, bool, str]] = self.attributes_to_validate + [ 26 ( 27 "has_valid_ncn", 28 True, 29 f"The neutral citation number of this {document_noun} is not valid", 30 ), 31 ] 32 33 super(NeutralCitationMixin, self).__init__(*args, **kwargs) 34 35 @cached_property 36 @abstractmethod 37 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 38 def neutral_citation(self) -> Optional[NeutralCitationString]: ... 39 40 @cached_property 41 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 42 def has_ncn(self) -> bool: 43 return self.neutral_citation is not None and self.neutral_citation != "" 44 45 @cached_property 46 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 47 def has_valid_ncn(self) -> bool: 48 if self.neutral_citation is None: 49 return True 50 return neutral_url(self.neutral_citation) is not None
class
NeutralCitationMixin(abc.ABC):
11class NeutralCitationMixin(ABC): 12 """ 13 A mixin class that provides functionality related to neutral citation. 14 15 The NeutralCitationMixin is intended to be used as a mixin in classes that represent legal documents 16 and need to handle neutral citation attributes and validation. 17 18 Notes: 19 - The document_noun attribute should be set in the child class that uses this mixin to provide 20 context-specific document noun strings for error messages and validation checks. 21 - The neutral_citation() method must be implemented in the child class to return the actual 22 neutral citation string for the legal document. 23 """ 24 25 def __init__(self, document_noun: str, *args: Any, **kwargs: Any) -> None: 26 self.attributes_to_validate: list[tuple[str, bool, str]] = self.attributes_to_validate + [ 27 ( 28 "has_valid_ncn", 29 True, 30 f"The neutral citation number of this {document_noun} is not valid", 31 ), 32 ] 33 34 super(NeutralCitationMixin, self).__init__(*args, **kwargs) 35 36 @cached_property 37 @abstractmethod 38 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 39 def neutral_citation(self) -> Optional[NeutralCitationString]: ... 40 41 @cached_property 42 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 43 def has_ncn(self) -> bool: 44 return self.neutral_citation is not None and self.neutral_citation != "" 45 46 @cached_property 47 @deprecated("Legacy usage of NCNs is deprecated; you should be moving to the Identifiers framework") 48 def has_valid_ncn(self) -> bool: 49 if self.neutral_citation is None: 50 return True 51 return neutral_url(self.neutral_citation) is not None
A mixin class that provides functionality related to neutral citation.
The NeutralCitationMixin is intended to be used as a mixin in classes that represent legal documents and need to handle neutral citation attributes and validation.
Notes: - The document_noun attribute should be set in the child class that uses this mixin to provide context-specific document noun strings for error messages and validation checks. - The neutral_citation() method must be implemented in the child class to return the actual neutral citation string for the legal document.
NeutralCitationMixin(document_noun: str, *args: Any, **kwargs: Any)
25 def __init__(self, document_noun: str, *args: Any, **kwargs: Any) -> None: 26 self.attributes_to_validate: list[tuple[str, bool, str]] = self.attributes_to_validate + [ 27 ( 28 "has_valid_ncn", 29 True, 30 f"The neutral citation number of this {document_noun} is not valid", 31 ), 32 ] 33 34 super(NeutralCitationMixin, self).__init__(*args, **kwargs)