def test_auto_blocking_small_bankr_docket(self): """Do we properly set small bankruptcy dockets to private?""" d = Docket() d.court = Court.objects.get(pk='akb') blocked, date_blocked = get_blocked_status(d) self.assertTrue(blocked, msg="Bankruptcy dockets with few entries " "should be blocked.") blocked, date_blocked = get_blocked_status(d, count_override=501) self.assertFalse(blocked, msg="Bankruptcy dockets with many entries " "should not be blocked") # This should stay blocked even though it's a big bankruptcy docket. d.blocked = True blocked, date_blocked = get_blocked_status(d, count_override=501) self.assertTrue(blocked, msg="Bankruptcy dockets that start blocked " "should stay blocked.")
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper. Works on either docket history report or docket report results. """ d.docket_number = docket_data['docket_number'] or d.docket_number d.date_filed = docket_data['date_filed'] or d.date_filed d.date_last_filing = docket_data.get('date_last_filing') or d.date_last_filing d.date_terminated = docket_data['date_terminated'] or d.date_terminated if d.case_name == "Unknown Case Title" or not d.case_name: d.case_name = docket_data['case_name'] or d.case_name d.case_name_short = cnt.make_case_name_short(d.case_name) or d.case_name_short d.cause = docket_data.get('cause') or d.cause d.nature_of_suit = docket_data.get('nature_of_suit') or d.nature_of_suit d.jury_demand = docket_data.get('jury_demand') or d.jury_demand d.jurisdiction_type = docket_data.get('jurisdiction') or d.jurisdiction_type judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get('assigned_to_str') or '' judges = get_candidate_judges(docket_data.get('referred_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get('referred_to_str') or '' d.blocked, d.date_blocked = get_blocked_status(d) return d
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper. Works on either docket history report or docket report (appellate or district) results. """ d = update_case_names(d, docket_data['case_name']) mark_ia_upload_needed(d) d.docket_number = docket_data['docket_number'] or d.docket_number d.date_filed = docket_data['date_filed'] or d.date_filed d.date_last_filing = docket_data.get( 'date_last_filing') or d.date_last_filing d.date_terminated = docket_data.get('date_terminated') or d.date_terminated d.cause = docket_data.get('cause') or d.cause d.nature_of_suit = docket_data.get('nature_of_suit') or d.nature_of_suit d.jury_demand = docket_data.get('jury_demand') or d.jury_demand d.jurisdiction_type = docket_data.get( 'jurisdiction') or d.jurisdiction_type d.mdl_status = docket_data.get('mdl_status') or d.mdl_status judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get('assigned_to_str') or '' judges = get_candidate_judges(docket_data.get('referred_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get('referred_to_str') or '' d.blocked, d.date_blocked = get_blocked_status(d) return d
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper""" d.docket_number = d.docket_number or docket_data['docket_number'] d.pacer_case_id = d.pacer_case_id or docket_data['pacer_case_id'] d.date_filed = d.date_filed or docket_data['date_filed'] d.date_terminated = d.date_terminated or docket_data['date_terminated'] d.case_name = d.case_name or docket_data['case_name'] d.case_name_short = d.case_name_short or cnt.make_case_name_short( d.case_name) d.cause = d.cause or docket_data['cause'] d.nature_of_suit = d.nature_of_suit or docket_data['nature_of_suit'] d.jury_demand = d.jury_demand or docket_data['jury_demand'] d.jurisdiction_type = d.jurisdiction_type or docket_data['jurisdiction'] judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get('assigned_to_str') or '' judges = get_candidate_judges(docket_data.get('referred_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get('referred_to_str') or '' d.blocked, d.date_blocked = get_blocked_status(d) return d
def update_docket_metadata(d: Docket, docket_data: Dict[str, Any]) -> Docket: """Update the Docket object with the data from Juriscraper. Works on either docket history report or docket report (appellate or district) results. """ d = update_case_names(d, docket_data["case_name"]) mark_ia_upload_needed(d, save_docket=False) d.docket_number = docket_data["docket_number"] or d.docket_number d.date_filed = docket_data.get("date_filed") or d.date_filed d.date_last_filing = ( docket_data.get("date_last_filing") or d.date_last_filing ) d.date_terminated = docket_data.get("date_terminated") or d.date_terminated d.cause = docket_data.get("cause") or d.cause d.nature_of_suit = docket_data.get("nature_of_suit") or d.nature_of_suit d.jury_demand = docket_data.get("jury_demand") or d.jury_demand d.jurisdiction_type = ( docket_data.get("jurisdiction") or d.jurisdiction_type ) d.mdl_status = docket_data.get("mdl_status") or d.mdl_status judges = get_candidate_judges( docket_data.get("assigned_to_str"), d.court_id, docket_data.get("date_filed"), ) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get("assigned_to_str") or "" judges = get_candidate_judges( docket_data.get("referred_to_str"), d.court_id, docket_data.get("date_filed"), ) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get("referred_to_str") or "" d.blocked, d.date_blocked = get_blocked_status(d) return d
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper""" d.docket_number = d.docket_number or docket_data['docket_number'] d.pacer_case_id = d.pacer_case_id or docket_data['pacer_case_id'] d.date_filed = d.date_filed or docket_data['date_filed'] d.date_terminated = d.date_terminated or docket_data['date_terminated'] d.case_name = d.case_name or docket_data['case_name'] d.case_name_short = d.case_name_short or cnt.make_case_name_short(d.case_name) d.cause = d.cause or docket_data['cause'] d.nature_of_suit = d.nature_of_suit or docket_data['nature_of_suit'] d.jury_demand = d.jury_demand or docket_data['jury_demand'] d.jurisdiction_type = d.jurisdiction_type or docket_data['jurisdiction'] judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get('assigned_to_str') or '' judges = get_candidate_judges(docket_data.get('referred_to_str'), d.court_id, docket_data['date_filed']) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get('referred_to_str') or '' d.blocked, d.date_blocked = get_blocked_status(d) return d
def process_free_opinion_result(self, row_pk, cnt): """Process a single result from the free opinion report""" result = PACERFreeDocumentRow.objects.get(pk=row_pk) result.court = Court.objects.get(pk=map_pacer_to_cl_id(result.court_id)) result.case_name = harmonize(result.case_name) result.case_name_short = cnt.make_case_name_short(result.case_name) row_copy = copy.copy(result) # If we don't do this, the doc's date_filed becomes the docket's # date_filed. Bad. delattr(row_copy, 'date_filed') # If we don't do this, we get the PACER court id and it crashes delattr(row_copy, 'court_id') # If we don't do this, the id of result tries to smash that of the docket. delattr(row_copy, 'id') try: with transaction.atomic(): docket = lookup_and_save(row_copy) if not docket: msg = "Unable to create docket for %s" % result logger.error(msg) result.error_msg = msg result.save() self.request.callbacks = None return docket.blocked, docket.date_blocked = get_blocked_status(docket) docket.save() de, de_created = DocketEntry.objects.update_or_create( docket=docket, entry_number=result.document_number, defaults={ 'date_filed': result.date_filed, 'description': result.description, }) rd, rd_created = RECAPDocument.objects.update_or_create( docket_entry=de, document_number=result.document_number, attachment_number=None, defaults={ 'pacer_doc_id': result.pacer_doc_id, 'document_type': RECAPDocument.PACER_DOCUMENT, 'is_free_on_pacer': True, }) except IntegrityError as e: msg = "Raised IntegrityError: %s" % e logger.error(msg) if self.request.retries == self.max_retries: result.error_msg = msg result.save() return raise self.retry(exc=e) except DatabaseError as e: msg = "Unable to complete database transaction:\n%s" % e logger.error(msg) result.error_msg = msg result.save() self.request.callbacks = None return if not rd_created and rd.is_available: # The item already exists and is available. Fantastic, mark it as free, # and call it a day. rd.is_free_on_pacer = True rd.save() result.delete() self.request.callbacks = None return return { 'result': result, 'rd_pk': rd.pk, 'pacer_court_id': result.court_id }
def process_free_opinion_result(self, row_pk, cnt): """Process a single result from the free opinion report""" result = PACERFreeDocumentRow.objects.get(pk=row_pk) result.court = Court.objects.get(pk=map_pacer_to_cl_id(result.court_id)) result.case_name = harmonize(result.case_name) result.case_name_short = cnt.make_case_name_short(result.case_name) row_copy = copy.copy(result) # If we don't do this, the doc's date_filed becomes the docket's # date_filed. Bad. delattr(row_copy, 'date_filed') # If we don't do this, we get the PACER court id and it crashes delattr(row_copy, 'court_id') # If we don't do this, the id of result tries to smash that of the docket. delattr(row_copy, 'id') try: with transaction.atomic(): docket = lookup_and_save(row_copy) if not docket: msg = "Unable to create docket for %s" % result logger.error(msg) result.error_msg = msg result.save() self.request.callbacks = None return docket.blocked, docket.date_blocked = get_blocked_status(docket) docket.save() de, de_created = DocketEntry.objects.update_or_create( docket=docket, entry_number=result.document_number, defaults={ 'date_filed': result.date_filed, 'description': result.description, } ) rd, rd_created = RECAPDocument.objects.update_or_create( docket_entry=de, document_number=result.document_number, attachment_number=None, defaults={ 'pacer_doc_id': result.pacer_doc_id, 'document_type': RECAPDocument.PACER_DOCUMENT, 'is_free_on_pacer': True, } ) except IntegrityError as e: msg = "Raised IntegrityError: %s" % e logger.error(msg) if self.request.retries == self.max_retries: result.error_msg = msg result.save() return raise self.retry(exc=e) except DatabaseError as e: msg = "Unable to complete database transaction:\n%s" % e logger.error(msg) result.error_msg = msg result.save() self.request.callbacks = None return if not rd_created and rd.is_available: # The item already exists and is available. Fantastic, mark it as free, # and call it a day. rd.is_free_on_pacer = True rd.save() result.delete() self.request.callbacks = None return return {'result': result, 'rd_pk': rd.pk, 'pacer_court_id': result.court_id}