Skip to content

Commit

Permalink
feat(clone_from_cl): optionally add clusters when a docket is cloned
Browse files Browse the repository at this point in the history
For use in #4467

Adds `--add-clusters` optional flag to be used when a docket is cloned
  • Loading branch information
grossir committed Sep 26, 2024
1 parent c2d657c commit 0de4c76
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cl/scrapers/management/commands/clone_from_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def clone_opinion_cluster(
session,
[docket_id],
add_docket_entries,
False,
False,
person_positions,
add_to_solr,
)[0]
Expand Down Expand Up @@ -350,6 +352,7 @@ def clone_docket(
docket_ids: list,
add_docket_entries: bool,
add_audio_files: bool,
add_clusters: bool,
person_positions: bool = False,
add_to_solr: bool = False,
object_type="search.Docket",
Expand Down Expand Up @@ -397,6 +400,13 @@ def clone_docket(
session, docket_data.get("audio_files", []), docket
)

if add_clusters:
docket_data = get_json_data(docket_url, session)
cluster_ids = [
c.split("/")[-2] for c in docket_data.get("clusters", [])
]
clone_opinion_cluster(session, cluster_ids, True, False)

continue
except model.DoesNotExist:
pass
Expand All @@ -410,7 +420,6 @@ def clone_docket(
"resource_uri",
"original_court_info",
"absolute_url",
"clusters",
"tags",
"panel",
"idb_data",
Expand Down Expand Up @@ -456,13 +465,17 @@ def clone_docket(
)

audio_files = docket_data.pop("audio_files", [])
clusters = docket_data.pop("clusters", [])

docket = model.objects.create(**docket_data)

dockets.append(docket)

if add_audio_files:
clone_audio_files(session, audio_files, docket)
if add_clusters:
cluster_ids = [c.split("/")[-2] for c in clusters]
clone_opinion_cluster(session, cluster_ids, True, False)

if add_docket_entries:
clone_docket_entries(session, docket.pk)
Expand Down Expand Up @@ -1105,6 +1118,14 @@ def add_arguments(self, parser):
"a docket.",
)

parser.add_argument(
"--add-clusters",
action="store_true",
default=False,
help="Use this flag to clone docket clusters when cloning "
"a docket.",
)

parser.add_argument(
"--clone-person-positions",
action="store_true",
Expand Down Expand Up @@ -1155,6 +1176,7 @@ def handle(self, *args, **options):
self.ids,
self.add_docket_entries,
options["add_audio_files"],
options["add_clusters"],
self.clone_person_positions,
self.add_to_solr,
self.type,
Expand Down

0 comments on commit 0de4c76

Please sign in to comment.