Skip to content

Commit

Permalink
Merge pull request #4497 from freelawproject/clone_from_cl_add_clusters
Browse files Browse the repository at this point in the history
feat(clone_from_cl): optionally add clusters when a docket is cloned
  • Loading branch information
grossir authored Oct 10, 2024
2 parents fd58057 + ba554d9 commit a74a5be
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 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 All @@ -360,6 +363,10 @@ def clone_docket(
:param session: a Requests session
:param docket_ids: a list of docket ids
:param add_docket_entries: flag to clone docket entries and recap docs
:param add_audio_files: flag to clone related audio files
when cloning a docket
:param add_clusters: flag to clone related opinion clusters when
cloning a docket
:param person_positions: True is we should clone person positions
:param person_positions: True is we should clone person positions
:param add_to_solr: True if we should add objects to solr
Expand Down Expand Up @@ -397,6 +404,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 +424,6 @@ def clone_docket(
"resource_uri",
"original_court_info",
"absolute_url",
"clusters",
"tags",
"panel",
"idb_data",
Expand Down Expand Up @@ -456,13 +469,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 +1122,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 +1180,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 a74a5be

Please sign in to comment.