-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
models.py
3977 lines (3650 loc) · 132 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
from datetime import datetime
from typing import Any, Dict, List, Tuple, TypeVar
import pghistory
import pytz
from asgiref.sync import sync_to_async
from celery.canvas import chain
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.postgres.indexes import HashIndex
from django.core.exceptions import ValidationError
from django.db import IntegrityError, models, transaction
from django.db.models import Q, QuerySet
from django.db.models.functions import MD5
from django.template import loader
from django.urls import NoReverseMatch, reverse
from django.utils import timezone
from django.utils.encoding import force_str
from django.utils.text import slugify
from eyecite import get_citations
from eyecite.tokenizers import HyperscanTokenizer
from localflavor.us.models import USPostalCodeField, USZipCodeField
from localflavor.us.us_states import OBSOLETE_STATES, USPS_CHOICES
from model_utils import FieldTracker
from cl.citations.utils import get_citation_depth_between_clusters
from cl.custom_filters.templatetags.text_filters import best_case_name
from cl.lib import fields
from cl.lib.date_time import midnight_pt
from cl.lib.model_helpers import (
CSVExportMixin,
linkify_orig_docket_number,
make_docket_number_core,
make_recap_path,
make_upload_path,
)
from cl.lib.models import AbstractDateTimeModel, AbstractPDF, s3_warning_note
from cl.lib.search_index_utils import (
InvalidDocumentError,
normalize_search_dicts,
null_map,
)
from cl.lib.storage import IncrementingAWSMediaStorage
from cl.lib.string_utils import trunc
from cl.lib.utils import deepgetattr
from cl.search.docket_sources import DocketSources
from cl.users.models import User
HYPERSCAN_TOKENIZER = HyperscanTokenizer(cache_dir=".hyperscan")
class PRECEDENTIAL_STATUS:
PUBLISHED = "Published"
UNPUBLISHED = "Unpublished"
ERRATA = "Errata"
SEPARATE = "Separate"
IN_CHAMBERS = "In-chambers"
RELATING_TO = "Relating-to"
UNKNOWN = "Unknown"
NAMES = (
(PUBLISHED, "Precedential"),
(UNPUBLISHED, "Non-Precedential"),
(ERRATA, "Errata"),
(SEPARATE, "Separate Opinion"),
(IN_CHAMBERS, "In-chambers"),
(RELATING_TO, "Relating-to orders"),
(UNKNOWN, "Unknown Status"),
)
@classmethod
def get_status_value(cls, name):
reverse_names = {value: key for key, value in cls.NAMES}
return reverse_names.get(name)
@classmethod
def get_status_value_reverse(cls, name):
reverse_names = {key: value for key, value in cls.NAMES}
return reverse_names.get(name)
class SOURCES:
COURT_WEBSITE = "C"
PUBLIC_RESOURCE = "R"
COURT_M_RESOURCE = "CR"
LAWBOX = "L"
LAWBOX_M_COURT = "LC"
LAWBOX_M_RESOURCE = "LR"
LAWBOX_M_COURT_RESOURCE = "LCR"
MANUAL_INPUT = "M"
INTERNET_ARCHIVE = "A"
BRAD_HEATH_ARCHIVE = "H"
COLUMBIA_ARCHIVE = "Z"
HARVARD_CASELAW = "U"
COURT_M_HARVARD = "CU"
DIRECT_COURT_INPUT = "D"
ANON_2020 = "Q"
ANON_2020_M_HARVARD = "QU"
COURT_M_RESOURCE_M_HARVARD = "CRU"
DIRECT_COURT_INPUT_M_HARVARD = "DU"
LAWBOX_M_HARVARD = "LU"
LAWBOX_M_COURT_M_HARVARD = "LCU"
LAWBOX_M_RESOURCE_M_HARVARD = "LRU"
LAWBOX_M_COURT_RESOURCE_M_HARVARD = "LCRU"
MANUAL_INPUT_M_HARVARD = "MU"
PUBLIC_RESOURCE_M_HARVARD = "RU"
COLUMBIA_M_INTERNET_ARCHIVE = "ZA"
COLUMBIA_M_DIRECT_COURT_INPUT = "ZD"
COLUMBIA_M_COURT = "ZC"
COLUMBIA_M_BRAD_HEATH_ARCHIVE = "ZH"
COLUMBIA_M_LAWBOX_COURT = "ZLC"
COLUMBIA_M_LAWBOX_RESOURCE = "ZLR"
COLUMBIA_M_LAWBOX_COURT_RESOURCE = "ZLCR"
COLUMBIA_M_RESOURCE = "ZR"
COLUMBIA_M_COURT_RESOURCE = "ZCR"
COLUMBIA_M_LAWBOX = "ZL"
COLUMBIA_M_MANUAL = "ZM"
COLUMBIA_M_ANON_2020 = "ZQ"
COLUMBIA_ARCHIVE_M_HARVARD = "ZU"
COLUMBIA_M_LAWBOX_M_HARVARD = "ZLU"
COLUMBIA_M_DIRECT_COURT_INPUT_M_HARVARD = "ZDU"
COLUMBIA_M_LAWBOX_M_RESOURCE_M_HARVARD = "ZLRU"
COLUMBIA_M_LAWBOX_M_COURT_RESOURCE_M_HARVARD = "ZLCRU"
COLUMBIA_M_COURT_M_HARVARD = "ZCU"
COLUMBIA_M_MANUAL_INPUT_M_HARVARD = "ZMU"
COLUMBIA_M_PUBLIC_RESOURCE_M_HARVARD = "ZRU"
COLUMBIA_M_LAWBOX_M_COURT_M_HARVARD = "ZLCU"
RECAP = "G"
NAMES = (
(COURT_WEBSITE, "court website"),
(PUBLIC_RESOURCE, "public.resource.org"),
(COURT_M_RESOURCE, "court website merged with resource.org"),
(LAWBOX, "lawbox"),
(LAWBOX_M_COURT, "lawbox merged with court"),
(LAWBOX_M_RESOURCE, "lawbox merged with resource.org"),
(LAWBOX_M_COURT_RESOURCE, "lawbox merged with court and resource.org"),
(MANUAL_INPUT, "manual input"),
(INTERNET_ARCHIVE, "internet archive"),
(BRAD_HEATH_ARCHIVE, "brad heath archive"),
(COLUMBIA_ARCHIVE, "columbia archive"),
(COLUMBIA_M_INTERNET_ARCHIVE, "columbia merged with internet archive"),
(
COLUMBIA_M_DIRECT_COURT_INPUT,
"columbia merged with direct court input",
),
(COLUMBIA_M_COURT, "columbia merged with court"),
(
COLUMBIA_M_BRAD_HEATH_ARCHIVE,
"columbia merged with brad heath archive",
),
(COLUMBIA_M_LAWBOX_COURT, "columbia merged with lawbox and court"),
(
COLUMBIA_M_LAWBOX_RESOURCE,
"columbia merged with lawbox and resource.org",
),
(
COLUMBIA_M_LAWBOX_COURT_RESOURCE,
"columbia merged with lawbox, court, and resource.org",
),
(COLUMBIA_M_RESOURCE, "columbia merged with resource.org"),
(
COLUMBIA_M_COURT_RESOURCE,
"columbia merged with court and resource.org",
),
(COLUMBIA_M_LAWBOX, "columbia merged with lawbox"),
(COLUMBIA_M_MANUAL, "columbia merged with manual input"),
(COLUMBIA_M_ANON_2020, "columbia merged with 2020 anonymous database"),
(
HARVARD_CASELAW,
"Harvard, Library Innovation Lab Case Law Access Project",
),
(COURT_M_HARVARD, "court website merged with Harvard"),
(DIRECT_COURT_INPUT, "direct court input"),
(ANON_2020, "2020 anonymous database"),
(ANON_2020_M_HARVARD, "2020 anonymous database merged with Harvard"),
(COURT_M_HARVARD, "court website merged with Harvard"),
(
COURT_M_RESOURCE_M_HARVARD,
"court website merged with public.resource.org and Harvard",
),
(
DIRECT_COURT_INPUT_M_HARVARD,
"direct court input merged with Harvard",
),
(LAWBOX_M_HARVARD, "lawbox merged with Harvard"),
(
LAWBOX_M_COURT_M_HARVARD,
"Lawbox merged with court website and Harvard",
),
(
LAWBOX_M_RESOURCE_M_HARVARD,
"Lawbox merged with public.resource.org and with Harvard",
),
(MANUAL_INPUT_M_HARVARD, "Manual input merged with Harvard"),
(PUBLIC_RESOURCE_M_HARVARD, "public.resource.org merged with Harvard"),
(COLUMBIA_ARCHIVE_M_HARVARD, "columbia archive merged with Harvard"),
(
COLUMBIA_M_LAWBOX_M_HARVARD,
"columbia archive merged with Lawbox and Harvard",
),
(
COLUMBIA_M_DIRECT_COURT_INPUT_M_HARVARD,
"columbia archive merged with direct court input and Harvard",
),
(
COLUMBIA_M_LAWBOX_M_RESOURCE_M_HARVARD,
"columbia archive merged with lawbox, public.resource.org and Harvard",
),
(
COLUMBIA_M_LAWBOX_M_COURT_RESOURCE_M_HARVARD,
"columbia archive merged with lawbox, court website, public.resource.org and Harvard",
),
(
COLUMBIA_M_COURT_M_HARVARD,
"columbia archive merged with court website and Harvard",
),
(
COLUMBIA_M_MANUAL_INPUT_M_HARVARD,
"columbia archive merged with manual input and Harvard",
),
(
COLUMBIA_M_PUBLIC_RESOURCE_M_HARVARD,
"columbia archive merged with public.resource.org and Harvard",
),
(
COLUMBIA_M_LAWBOX_M_COURT_M_HARVARD,
"columbia archive merged with lawbox, court website and Harvard",
),
(
RECAP,
"recap",
),
)
@pghistory.track()
class OriginatingCourtInformation(AbstractDateTimeModel):
"""Lower court metadata to associate with appellate cases.
For example, if you appeal from a district court to a circuit court, the
district court information would be in here. You may wonder, "Why do we
duplicate this information?" Well:
1. We don't want to update the lower court case based on information
we learn in the upper court. Say they have a conflict? Which do we
trust?
2. We may have the docket from the upper court without ever getting
docket information for the lower court. If that happens, would we
create a docket for the lower court using only the info in the
upper court. That seems bad.
The other thought you might have is, "Why not just associate this directly
with the docket object —-- why do we have a 1to1 join between them?" This
was a difficult data modelling decision. There are a few answers:
1. Most cases in the RECAP Archive are not appellate cases. For those
cases, the extra fields for this information would just pollute the
Docket namespace.
2. In general, we prefer to have Docket.originating_court_data.field
than, Docket.ogc_field.
"""
docket_number = models.TextField(
help_text="The docket number in the lower court.", blank=True
)
assigned_to = models.ForeignKey(
"people_db.Person",
help_text="The judge the case was assigned to.",
related_name="original_court_info",
on_delete=models.RESTRICT,
null=True,
blank=True,
)
assigned_to_str = models.TextField(
help_text="The judge that the case was assigned to, as a string.",
blank=True,
)
ordering_judge = models.ForeignKey(
"people_db.Person",
related_name="+",
help_text="The judge that issued the final order in the case.",
on_delete=models.RESTRICT,
null=True,
blank=True,
)
ordering_judge_str = models.TextField(
help_text=(
"The judge that issued the final order in the case, as a "
"string."
),
blank=True,
)
court_reporter = models.TextField(
help_text="The court reporter responsible for the case.", blank=True
)
date_disposed = models.DateField(
help_text="The date the case was disposed at the lower court.",
blank=True,
null=True,
)
date_filed = models.DateField(
help_text="The date the case was filed in the lower court.",
blank=True,
null=True,
)
date_judgment = models.DateField(
help_text="The date of the order or judgment in the lower court.",
blank=True,
null=True,
)
date_judgment_eod = models.DateField(
help_text=(
"The date the judgment was Entered On the Docket at the "
"lower court."
),
blank=True,
null=True,
)
date_filed_noa = models.DateField(
help_text="The date the notice of appeal was filed for the case.",
blank=True,
null=True,
)
date_received_coa = models.DateField(
help_text="The date the case was received at the court of appeals.",
blank=True,
null=True,
)
@property
def administrative_link(self):
return linkify_orig_docket_number(
self.docket.appeal_from_str, self.docket_number
)
def get_absolute_url(self) -> str:
return self.docket.get_absolute_url()
class Meta:
verbose_name_plural = "Originating Court Information"
@pghistory.track(
pghistory.UpdateEvent(
condition=pghistory.AnyChange(exclude_auto=True), row=pghistory.Old
),
pghistory.DeleteEvent(),
exclude=["view_count"],
)
class Docket(AbstractDateTimeModel, DocketSources):
"""A class to sit above OpinionClusters, Audio files, and Docket Entries,
and link them together.
"""
source = models.SmallIntegerField(
help_text="contains the source of the Docket.",
choices=DocketSources.SOURCE_CHOICES,
)
court = models.ForeignKey(
"Court",
help_text="The court where the docket was filed",
on_delete=models.RESTRICT,
db_index=True,
related_name="dockets",
)
appeal_from = models.ForeignKey(
"Court",
help_text=(
"In appellate cases, this is the lower court or "
"administrative body where this case was originally heard. "
"This field is frequently blank due to it not being "
"populated historically or due to our inability to "
"normalize the value in appeal_from_str."
),
related_name="+",
on_delete=models.RESTRICT,
blank=True,
null=True,
)
parent_docket = models.ForeignKey(
"self",
help_text="In criminal cases (and some magistrate) PACER creates "
"a parent docket and one or more child dockets. Child dockets "
"contain docket information for each individual defendant "
"while parent dockets are a superset of all docket entries.",
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="child_dockets",
)
appeal_from_str = models.TextField(
help_text=(
"In appellate cases, this is the lower court or "
"administrative body where this case was originally heard. "
"This field is frequently blank due to it not being "
"populated historically. This field may have values when "
"the appeal_from field does not. That can happen if we are "
"unable to normalize the value in this field."
),
blank=True,
)
originating_court_information = models.OneToOneField(
OriginatingCourtInformation,
help_text="Lower court information for appellate dockets",
related_name="docket",
on_delete=models.SET_NULL,
blank=True,
null=True,
)
idb_data = models.OneToOneField(
"recap.FjcIntegratedDatabase",
help_text=(
"Data from the FJC Integrated Database associated with this "
"case."
),
related_name="docket",
on_delete=models.SET_NULL,
blank=True,
null=True,
)
tags = models.ManyToManyField(
"search.Tag",
help_text="The tags associated with the docket.",
related_name="dockets",
blank=True,
)
html_documents = GenericRelation(
"recap.PacerHtmlFiles",
help_text="Original HTML files collected from PACER.",
related_query_name="dockets",
null=True,
blank=True,
)
assigned_to = models.ForeignKey(
"people_db.Person",
related_name="assigning",
help_text="The judge the case was assigned to.",
on_delete=models.RESTRICT,
null=True,
blank=True,
)
assigned_to_str = models.TextField(
help_text="The judge that the case was assigned to, as a string.",
blank=True,
)
referred_to = models.ForeignKey(
"people_db.Person",
related_name="referring",
help_text="The judge to whom the 'assigned_to' judge is delegated.",
on_delete=models.RESTRICT,
null=True,
blank=True,
)
referred_to_str = models.TextField(
help_text="The judge that the case was referred to, as a string.",
blank=True,
)
panel = models.ManyToManyField(
"people_db.Person",
help_text=(
"The empaneled judges for the case. Currently an unused "
"field but planned to be used in conjunction with the "
"panel_str field."
),
related_name="empanelled_dockets",
blank=True,
)
panel_str = models.TextField(
help_text=(
"The initials of the judges on the panel that heard this "
"case. This field is similar to the 'judges' field on "
"the cluster, but contains initials instead of full judge "
"names, and applies to the case on the whole instead of "
"only to a specific decision."
),
blank=True,
)
parties = models.ManyToManyField(
"people_db.Party",
help_text="The parties involved in the docket",
related_name="dockets",
through="people_db.PartyType",
blank=True,
)
date_last_index = models.DateTimeField(
help_text="The last moment that the item was indexed in Solr.",
null=True,
blank=True,
)
date_cert_granted = models.DateField(
help_text="date cert was granted for this case, if applicable",
blank=True,
null=True,
)
date_cert_denied = models.DateField(
help_text="the date cert was denied for this case, if applicable",
blank=True,
null=True,
)
date_argued = models.DateField(
help_text="the date the case was argued",
blank=True,
null=True,
)
date_reargued = models.DateField(
help_text="the date the case was reargued",
blank=True,
null=True,
)
date_reargument_denied = models.DateField(
help_text="the date the reargument was denied",
blank=True,
null=True,
)
date_filed = models.DateField(
help_text="The date the case was filed.", blank=True, null=True
)
date_terminated = models.DateField(
help_text="The date the case was terminated.", blank=True, null=True
)
date_last_filing = models.DateField(
help_text=(
"The date the case was last updated in the docket, as shown "
"in PACER's Docket History report or iquery page."
),
blank=True,
null=True,
)
case_name_short = models.TextField(
help_text="The abridged name of the case, often a single word, e.g. "
"'Marsh'",
blank=True,
)
case_name = models.TextField(
help_text="The standard name of the case", blank=True
)
case_name_full = models.TextField(
help_text="The full name of the case", blank=True
)
slug = models.SlugField(
help_text="URL that the document should map to (the slug)",
max_length=75,
db_index=False,
blank=True,
)
docket_number = models.TextField( # nosemgrep
help_text="The docket numbers of a case, can be consolidated and "
"quite long. In some instances they are too long to be "
"indexed by postgres and we store the full docket in "
"the correction field on the Opinion Cluster.",
blank=True,
null=True,
)
docket_number_core = models.CharField(
help_text=(
"For federal district court dockets, this is the most "
"distilled docket number available. In this field, the "
"docket number is stripped down to only the year and serial "
"digits, eliminating the office at the beginning, letters "
"in the middle, and the judge at the end. Thus, a docket "
"number like 2:07-cv-34911-MJL becomes simply 0734911. This "
"is the format that is provided by the IDB and is useful "
"for de-duplication types of activities which otherwise get "
"messy. We use a char field here to preserve leading zeros."
),
# PACER doesn't do consolidated case numbers, so this can be small.
max_length=20,
blank=True,
db_index=True,
)
federal_dn_office_code = models.CharField(
help_text="A one digit statistical code (either alphabetic or numeric) "
"of the office within the federal district. In this "
"example, 2:07-cv-34911-MJL, the 2 preceding "
"the : is the office code.",
max_length=3,
blank=True,
)
federal_dn_case_type = models.CharField(
help_text="Case type, e.g., civil (cv), magistrate (mj), criminal (cr), "
"petty offense (po), and miscellaneous (mc). These codes "
"can be upper case or lower case, and may vary in number of "
"characters.",
max_length=6,
blank=True,
)
federal_dn_judge_initials_assigned = models.CharField(
help_text="A typically three-letter upper cased abbreviation "
"of the judge's initials. In the example 2:07-cv-34911-MJL, "
"MJL is the judge's initials. Judge initials change if a "
"new judge takes over a case.",
max_length=5,
blank=True,
)
federal_dn_judge_initials_referred = models.CharField(
help_text="A typically three-letter upper cased abbreviation "
"of the judge's initials. In the example 2:07-cv-34911-MJL-GOG, "
"GOG is the magistrate judge initials.",
max_length=5,
blank=True,
)
federal_defendant_number = models.SmallIntegerField(
help_text="A unique number assigned to each defendant in a case, "
"typically found in pacer criminal cases as a -1, -2 after "
"the judge initials. Example: 1:14-cr-10363-RGS-1.",
null=True,
blank=True,
)
# Nullable for unique constraint requirements.
pacer_case_id = fields.CharNullField(
help_text="The case ID provided by PACER.",
max_length=100,
blank=True,
null=True,
db_index=True,
)
cause = models.CharField(
help_text="The cause for the case.",
max_length=2000, # Was 200, 500, 1000
blank=True,
)
nature_of_suit = models.CharField(
help_text="The nature of suit code from PACER.",
max_length=1000, # Was 100, 500
blank=True,
)
jury_demand = models.CharField(
help_text="The compensation demand.", max_length=500, blank=True
)
jurisdiction_type = models.CharField(
help_text=(
"Stands for jurisdiction in RECAP XML docket. For example, "
"'Diversity', 'U.S. Government Defendant'."
),
max_length=100,
blank=True,
)
appellate_fee_status = models.TextField(
help_text=(
"The status of the fee in the appellate court. Can be used "
"as a hint as to whether the government is the appellant "
"(in which case the fee is waived)."
),
blank=True,
)
appellate_case_type_information = models.TextField(
help_text=(
"Information about a case from the appellate docket in "
"PACER. For example, 'civil, private, bankruptcy'."
),
blank=True,
)
mdl_status = models.CharField(
help_text="The MDL status of a case before the Judicial Panel for "
"Multidistrict Litigation",
max_length=100,
blank=True,
)
filepath_local = models.FileField(
help_text="Path to RECAP's Docket XML page as provided by the "
"original RECAP architecture. These fields are for backup purposes "
f"only. {s3_warning_note}",
upload_to=make_recap_path,
storage=IncrementingAWSMediaStorage(),
max_length=1000,
blank=True,
)
filepath_ia = models.CharField(
help_text="Path to the Docket XML page in The Internet Archive",
max_length=1000,
blank=True,
)
filepath_ia_json = models.CharField(
help_text="Path to the docket JSON page in the Internet Archive",
max_length=1000,
blank=True,
)
ia_upload_failure_count = models.SmallIntegerField(
help_text="Number of times the upload to the Internet Archive failed.",
null=True,
blank=True,
)
ia_needs_upload = models.BooleanField(
help_text=(
"Does this item need to be uploaded to the Internet "
"Archive? I.e., has it changed? This field is important "
"because it keeps track of the status of all the related "
"objects to the docket. For example, if a related docket "
"entry changes, we need to upload the item to IA, but we "
"can't easily check that."
),
blank=True,
null=True,
)
ia_date_first_change = models.DateTimeField(
help_text=(
"The moment when this item first changed and was marked as "
"needing an upload. Used for determining when to upload an "
"item."
),
null=True,
blank=True,
)
view_count = models.IntegerField(
help_text="The number of times the docket has been seen.", default=0
)
date_blocked = models.DateField(
help_text=(
"The date that this opinion was blocked from indexing by "
"search engines"
),
blank=True,
null=True,
db_index=True,
)
blocked = models.BooleanField(
help_text=(
"Whether a document should be blocked from indexing by "
"search engines"
),
default=False,
)
es_pa_field_tracker = FieldTracker(fields=["docket_number", "court_id"])
es_oa_field_tracker = FieldTracker(
fields=[
"date_argued",
"date_reargued",
"date_reargument_denied",
"docket_number",
"slug",
]
)
es_rd_field_tracker = FieldTracker(
fields=[
"docket_number",
"case_name",
"case_name_short",
"case_name_full",
"nature_of_suit",
"cause",
"jury_demand",
"jurisdiction_type",
"date_argued",
"date_filed",
"date_terminated",
"assigned_to_id",
"assigned_to_str",
"referred_to_id",
"referred_to_str",
"slug",
"pacer_case_id",
"source",
]
)
es_o_field_tracker = FieldTracker(
fields=[
"court_id",
"docket_number",
"date_argued",
"date_reargued",
"date_reargument_denied",
]
)
class Meta:
constraints = [
models.UniqueConstraint(
MD5("docket_number"),
"pacer_case_id",
"court_id",
name="unique_docket_per_court",
),
]
indexes = [
models.Index(fields=["court_id", "id"]),
models.Index(
fields=["court_id", "docket_number_core", "pacer_case_id"],
name="district_court_docket_lookup_idx",
),
HashIndex("docket_number", name="hash_docket_number_lookup_idx"),
]
def __str__(self) -> str:
if self.case_name:
return force_str(f"{self.pk}: {self.case_name}")
else:
return f"{self.pk}"
def save(self, update_fields=None, *args, **kwargs):
self.slug = slugify(trunc(best_case_name(self), 75))
if self.docket_number and not self.docket_number_core:
self.docket_number_core = make_docket_number_core(
self.docket_number
)
if self.source in self.RECAP_SOURCES():
for field in ["pacer_case_id", "docket_number"]:
if (
field == "pacer_case_id"
and getattr(self, "court", None)
and self.court.jurisdiction == Court.FEDERAL_APPELLATE
):
continue
if not getattr(self, field, None):
raise ValidationError(
f"'{field}' cannot be Null or empty in RECAP dockets."
)
if update_fields is not None:
update_fields = {"slug", "docket_number_core"}.union(update_fields)
try:
# Without a transaction wrapper, a failure will invalidate outer transactions
with transaction.atomic():
super().save(update_fields=update_fields, *args, **kwargs)
except IntegrityError:
# Temporary patch while we solve #3359
# If the error is not related to `date_modified` it will raise again
self.date_modified = timezone.now()
super().save(update_fields=update_fields, *args, **kwargs)
def get_absolute_url(self) -> str:
return reverse("view_docket", args=[self.pk, self.slug])
def add_recap_source(self):
if self.source == self.DEFAULT:
self.source = self.RECAP_AND_SCRAPER
elif self.source in self.NON_RECAP_SOURCES():
# Simply add the RECAP value to the other value.
self.source = self.source + self.RECAP
def add_opinions_source(self, scraper_source: int):
match scraper_source:
case self.COLUMBIA:
non_source_list = self.NON_COLUMBIA_SOURCES()
case self.SCRAPER:
non_source_list = self.NON_SCRAPER_SOURCES()
case self.HARVARD:
non_source_list = self.NON_HARVARD_SOURCES()
case _:
return
if self.source in non_source_list:
# Simply add the new source value to the other value.
self.source = self.source + scraper_source
@property
def authorities(self):
"""Returns a queryset that can be used for querying and caching
authorities.
"""
return OpinionsCitedByRECAPDocument.objects.filter(
citing_document__docket_entry__docket_id=self.pk
)
async def ahas_authorities(self):
return await self.authorities.aexists()
@property
def authority_count(self):
return self.authorities.count()
@property
def authorities_with_data(self):
"""Returns a queryset of this document's authorities for
eventual injection into a view template.
The returned queryset is sorted by the depth field.
"""
return build_authorities_query(self.authorities)
def add_idb_source(self):
if self.source in self.NON_IDB_SOURCES():
self.source = self.source + self.IDB
def add_anon_2020_source(self) -> None:
if self.source in self.NON_ANON_2020_SOURCES():
self.source = self.source + self.ANON_2020
@property
def pacer_court_id(self):
if hasattr(self, "_pacer_court_id"):
return self._pacer_court_id
from cl.lib.pacer import map_cl_to_pacer_id
pacer_court_id = map_cl_to_pacer_id(self.court.pk)
self._pacer_court_id = pacer_court_id
return pacer_court_id
def pacer_district_url(self, path):
if not self.pacer_case_id or (
self.court.jurisdiction == Court.FEDERAL_APPELLATE
):
return None
return f"https://ecf.{self.pacer_court_id}.uscourts.gov/cgi-bin/{path}?{self.pacer_case_id}"
def pacer_appellate_url_with_caseId(self, path):
return (
f"https://ecf.{self.pacer_court_id}.uscourts.gov"
f"{path}"
"servlet=CaseSummary.jsp&"
f"caseId={self.pacer_case_id}&"
"incOrigDkt=Y&"
"incDktEntries=Y"
)
def pacer_appellate_url_with_caseNum(self, path):
return (
f"https://ecf.{self.pacer_court_id}.uscourts.gov"
f"{path}"
"servlet=CaseSummary.jsp&"
f"caseNum={self.docket_number}&"
"incOrigDkt=Y&"
"incDktEntries=Y"
)
def pacer_acms_url(self):
return (
f"https://{self.pacer_court_id}-showdoc.azurewebsites.us/"
f"{self.docket_number}"
)
@property
def pacer_docket_url(self):
if self.court.jurisdiction == Court.FEDERAL_APPELLATE:
if self.court.pk in ["ca5", "ca7", "ca11"]:
path = "/cmecf/servlet/TransportRoom?"
else:
path = "/n/beam/servlet/TransportRoom?"
if not self.pacer_case_id:
return self.pacer_appellate_url_with_caseNum(path)
elif self.pacer_case_id.count("-") > 1:
return self.pacer_acms_url()
else:
return self.pacer_appellate_url_with_caseId(path)
else:
return self.pacer_district_url("DktRpt.pl")
@property
def pacer_alias_url(self):
return self.pacer_district_url("qryAlias.pl")
@property
def pacer_associated_cases_url(self):
return self.pacer_district_url("qryAscCases.pl")
@property
def pacer_attorney_url(self):
return self.pacer_district_url("qryAttorneys.pl")
@property
def pacer_case_file_location_url(self):
return self.pacer_district_url("QryRMSLocation.pl")
@property
def pacer_summary_url(self):
return self.pacer_district_url("qrySummary.pl")
@property
def pacer_deadlines_and_hearings_url(self):
return self.pacer_district_url("SchedQry.pl")
@property
def pacer_filers_url(self):
return self.pacer_district_url("FilerQry.pl")
@property
def pacer_history_and_documents_url(self):
return self.pacer_district_url("HistDocQry.pl")
@property
def pacer_party_url(self):
return self.pacer_district_url("qryParties.pl")
@property
def pacer_related_transactions_url(self):
return self.pacer_district_url("RelTransactQry.pl")
@property
def pacer_status_url(self):
return self.pacer_district_url("StatusQry.pl")
@property
def pacer_view_doc_url(self):
return self.pacer_district_url("qryDocument.pl")
def as_search_list(self):
"""Create list of search dicts from a single docket. This should be
faster than creating a search dict per document on the docket.
"""
search_list = []
# Docket
out = {
"docketNumber": self.docket_number,