Skip to content

Commit

Permalink
Merge pull request #1625 from wittejm/requested-changes-form-filename…
Browse files Browse the repository at this point in the history
…s-and-stuff

Requested changes: form filenames
  • Loading branch information
wittejm authored Sep 23, 2022
2 parents 4629aa1 + db6c2cc commit f9529cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def build_zip(record_summary: RecordSummary, user_information: Dict[str, str]) -

pdf_with_warnings = FormFilling._build_pdf_for_case(case_without_deleted_charges, user_information, sid)
if pdf_with_warnings:
pdf, internal_file_name, warnings = pdf_with_warnings
file_name = f"{case_without_deleted_charges.summary.name}_{case_without_deleted_charges.summary.case_number}_{internal_file_name}"
pdf, base_file_name, warnings = pdf_with_warnings
file_name = f"{case_without_deleted_charges.summary.name}_{case_without_deleted_charges.summary.case_number}_{base_file_name}"
file_path = path.join(temp_dir, file_name)
writer = PdfWriter()
writer.addpages(pdf.pages)
Expand All @@ -108,7 +108,7 @@ def build_zip(record_summary: RecordSummary, user_information: Dict[str, str]) -

# TODO: Extract to method
pdf = FormFilling._build_certificate_of_mailing_pdf(user_information)
file_name = f"certificate_of_mailing.pdf"
file_name = f"OSP_Form.pdf"
file_path = path.join(temp_dir, file_name)
writer = PdfWriter()
writer.addpages(pdf.pages)
Expand Down Expand Up @@ -137,7 +137,7 @@ def _unify_sids(record_summary: RecordSummary) -> str:
@staticmethod
def _build_certificate_of_mailing_pdf(user_information: Dict[str, str]) -> PdfReader:
form = from_dict(data_class=CertificateFormData, data=user_information)
pdf_path = path.join(Path(__file__).parent, "files", f"certificate_of_mailing.pdf")
pdf_path = path.join(Path(__file__).parent, "files", f"OSP_Form.pdf")
pdf = PdfReader(pdf_path)
for field in pdf.Root.AcroForm.Fields:
field_name = field.T.lower().replace(" ", "_").replace("(", "").replace(")", "")
Expand Down Expand Up @@ -265,7 +265,8 @@ def _build_pdf_for_eligible_case(
form = from_dict(data_class=FormDataWithOrder, data=form_data_dict)
location = case.summary.location.lower()
pdf_path = FormFilling._build_pdf_path(location, convictions)
file_name = os.path.basename(pdf_path)
base_file_name = FormFilling._build_base_file_name(location, convictions)
file_name = os.path.basename(base_file_name)
pdf = PdfReader(pdf_path)
for field in pdf.Root.AcroForm.Fields:
field_name = field.T.lower().replace(" ", "_").replace("(", "").replace(")", "")
Expand Down Expand Up @@ -364,3 +365,14 @@ def _build_pdf_path(location: str, convictions: List[Charge]) -> str:
return path.join(Path(__file__).parent, "files", "oregon_with_arrest_order.pdf")
else:
return path.join(Path(__file__).parent, "files", "oregon.pdf")

@staticmethod
def _build_base_file_name(location: str, convictions: List[Charge]) -> str:
# Douglas and Umatilla counties explicitly want the "Order" part of the old forms too.
if location in ["douglas", "umatilla"]:
if convictions:
return path.join(Path(__file__).parent, "files", f"{location}_with_conviction_order.pdf")
else:
return path.join(Path(__file__).parent, "files", f"{location}_with_arrest_order.pdf")
else:
return path.join(Path(__file__).parent, "files", f"{location}.pdf")

0 comments on commit f9529cf

Please sign in to comment.