def update_docket_appellate_metadata(d, docket_data): """Update the metadata specific to appellate cases.""" if not any([ docket_data.get('originating_court_information'), docket_data.get('appeal_from'), docket_data.get('panel') ]): # Probably not appellate. return d, None d.panel_str = ', '.join(docket_data.get('panel', [])) or d.panel_str d.appellate_fee_status = docket_data.get('fee_status', '') or d.appellate_fee_status d.appellate_case_type_information = docket_data.get( 'case_type_information', '') or d.appellate_case_type_information d.appeal_from_str = docket_data.get('appeal_from', '') or d.appeal_from_str # Do originating court information dict og_info = docket_data.get('originating_court_information') if not og_info: return d, None if og_info.get('court_id'): cl_id = map_pacer_to_cl_id(og_info['court_id']) if Court.objects.filter(pk=cl_id).exists(): # Ensure the court exists. Sometimes PACER does weird things, # like in 14-1743 in CA3, where it says the court_id is 'uspci'. # If we don't do this check, the court ID could be invalid, and # our whole save of the docket fails. d.appeal_from_id = cl_id if d.originating_court_information: d_og_info = d.originating_court_information else: d_og_info = OriginatingCourtInformation() # Ensure we don't share A-Numbers, which can sometimes be in the docket # number field. docket_number = og_info.get('docket_number', '') or d_og_info.docket_number docket_number, _ = anonymize(docket_number) d_og_info.docket_number = docket_number d_og_info.court_reporter = og_info.get('court_reporter', '') or d_og_info.court_reporter d_og_info.date_disposed = og_info.get( 'date_disposed') or d_og_info.date_disposed d_og_info.date_filed = og_info.get('date_filed') or d_og_info.date_filed d_og_info.date_judgment = og_info.get( 'date_judgment') or d_og_info.date_judgment d_og_info.date_judgment_eod = og_info.get( 'date_judgment_eod') or d_og_info.date_judgment_eod d_og_info.date_filed_noa = og_info.get( 'date_filed_noa') or d_og_info.date_filed_noa d_og_info.date_received_coa = og_info.get( 'date_received_coa') or d_og_info.date_received_coa d_og_info.assigned_to_str = og_info.get( 'assigned_to') or d_og_info.assigned_to_str d_og_info.ordering_judge_str = og_info.get( 'ordering_judge') or d_og_info.ordering_judge_str if not all([d.appeal_from_id, d_og_info.date_filed]): # Can't do judge lookups. Call it quits. return d, d_og_info if og_info.get('assigned_to'): judges = get_candidate_judges(og_info['assigned_to'], d.appeal_from_id, d_og_info.date_filed) if judges is not None and len(judges) == 1: d_og_info.assigned_to = judges[0] if og_info.get('ordering_judge'): judges = get_candidate_judges(og_info['ordering_judge'], d.appeal_from_id, d_og_info.date_filed) if judges is not None and len(judges) == 1: d_og_info.ordering_judge = judges[0] return d, d_og_info
def update_docket_appellate_metadata(d, docket_data): """Update the metadata specific to appellate cases.""" if not any( [ docket_data.get("originating_court_information"), docket_data.get("appeal_from"), docket_data.get("panel"), ] ): # Probably not appellate. return d, None d.panel_str = ", ".join(docket_data.get("panel", [])) or d.panel_str d.appellate_fee_status = ( docket_data.get("fee_status", "") or d.appellate_fee_status ) d.appellate_case_type_information = ( docket_data.get("case_type_information", "") or d.appellate_case_type_information ) d.appeal_from_str = docket_data.get("appeal_from", "") or d.appeal_from_str # Do originating court information dict og_info = docket_data.get("originating_court_information") if not og_info: return d, None if og_info.get("court_id"): cl_id = map_pacer_to_cl_id(og_info["court_id"]) if Court.objects.filter(pk=cl_id).exists(): # Ensure the court exists. Sometimes PACER does weird things, # like in 14-1743 in CA3, where it says the court_id is 'uspci'. # If we don't do this check, the court ID could be invalid, and # our whole save of the docket fails. d.appeal_from_id = cl_id if d.originating_court_information: d_og_info = d.originating_court_information else: d_og_info = OriginatingCourtInformation() # Ensure we don't share A-Numbers, which can sometimes be in the docket # number field. docket_number = og_info.get("docket_number", "") or d_og_info.docket_number docket_number, _ = anonymize(docket_number) d_og_info.docket_number = docket_number d_og_info.court_reporter = ( og_info.get("court_reporter", "") or d_og_info.court_reporter ) d_og_info.date_disposed = ( og_info.get("date_disposed") or d_og_info.date_disposed ) d_og_info.date_filed = og_info.get("date_filed") or d_og_info.date_filed d_og_info.date_judgment = ( og_info.get("date_judgment") or d_og_info.date_judgment ) d_og_info.date_judgment_eod = ( og_info.get("date_judgment_eod") or d_og_info.date_judgment_eod ) d_og_info.date_filed_noa = ( og_info.get("date_filed_noa") or d_og_info.date_filed_noa ) d_og_info.date_received_coa = ( og_info.get("date_received_coa") or d_og_info.date_received_coa ) d_og_info.assigned_to_str = ( og_info.get("assigned_to") or d_og_info.assigned_to_str ) d_og_info.ordering_judge_str = ( og_info.get("ordering_judge") or d_og_info.ordering_judge_str ) if not all([d.appeal_from_id, d_og_info.date_filed]): # Can't do judge lookups. Call it quits. return d, d_og_info lookup_judge_by_full_name_and_set_attr( d_og_info, "assigned_to", og_info.get("assigned_to"), d.appeal_from_id, d_og_info.date_filed, ) lookup_judge_by_full_name_and_set_attr( d_og_info, "ordering_judge", og_info.get("ordering_judge"), d.appeal_from_id, d_og_info.date_filed, ) return d, d_og_info