Skip to content

Commit

Permalink
feat(court): Adds is_bankruptcy_court helper function
Browse files Browse the repository at this point in the history
This commit introduces a new helper function, `is_bankruptcy_court`, which checks if a given court ID corresponds to a bankruptcy court.
  • Loading branch information
ERosendo committed Feb 4, 2025
1 parent 3128bbf commit 0e94712
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cl/corpus_importer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ async def mark_ia_upload_needed(d: Docket, save_docket: bool) -> None:
await d.asave()


def is_bankruptcy_court(court_id: str) -> bool:
"""Checks if a given court ID corresponds to a bankruptcy court.
This function queries the database to determine if the provided court
ID is associated with a federal bankruptcy court.
Args:
court_id: The ID of the court to check (string).
Returns:
True if the court ID corresponds to a bankruptcy court, False otherwise
(boolean).
"""
bankr_court_ids = Court.federal_courts.bankruptcy_courts()
return bankr_court_ids.filter(pk=court_id).exists()


def is_appellate_court(court_id: str) -> bool:
"""Checks if the given court_id belongs to an appellate court.
Expand Down
3 changes: 2 additions & 1 deletion cl/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from cl.alerts.models import Alert
from cl.audio.models import Audio
from cl.corpus_importer.utils import is_bankruptcy_court
from cl.custom_filters.templatetags.text_filters import (
best_case_name,
html_decode,
Expand Down Expand Up @@ -1253,7 +1254,7 @@ def prepare_parties(self, instance):
# available.
party_from_case_name = (
get_parties_from_case_name_bankr(instance.case_name)
if instance.court_id.endswith("b")
if is_bankruptcy_court(instance.court_id)
else get_parties_from_case_name(instance.case_name)
)
out["party"] = party_from_case_name if party_from_case_name else []
Expand Down
3 changes: 2 additions & 1 deletion cl/search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
from cl.audio.models import Audio
from cl.celery_init import app
from cl.corpus_importer.utils import is_bankruptcy_court
from cl.lib.elasticsearch_utils import build_daterange_query
from cl.lib.search_index_utils import (
get_parties_from_case_name,
Expand Down Expand Up @@ -323,7 +324,7 @@ def document_fields_to_update(
get_parties_from_case_name_bankr(
main_instance.case_name
)
if main_instance.court_id.endswith("b")
if is_bankruptcy_court(main_instance.court_id)
else get_parties_from_case_name(
main_instance.case_name
)
Expand Down

0 comments on commit 0e94712

Please sign in to comment.