Skip to content

Commit 5ca2a5a

Browse files
Alan HermannsAlan Hermanns
authored andcommitted
merged master
2 parents 6db3384 + 4f6ebfb commit 5ca2a5a

18 files changed

Lines changed: 49 additions & 260 deletions

src/backend/expungeservice/form_filling.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ class FormFilling:
616616
COUNTIES_NEEDING_CONVICTION_OR_ARREST_ORDER = ["multnomah"]
617617
COUNTIES_NEEDING_COUNTY_SPECIFIC_DOWNLOAD_NAME : List[str] = []
618618
OSP_PDF_NAME = "OSP_Form"
619-
#COMPILED_PDF_NAME = "COMPILED_MOTIONS"
620619

621620
@staticmethod
622621
def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, str], summary: bytes, summary_filename: str) -> Tuple[str, str]:
@@ -649,20 +648,11 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
649648
osp_file_info = FormFilling._create_and_write_pdf(user_information_dict_2, temp_dir)
650649
zip_file.write(*osp_file_info[0:2])
651650

652-
#todo: refactor and build separate method to compose compiled
653651
if all_motions_to_set_aside:
654-
compiled = PdfWriter()
655-
compiled.addpages(PdfReader(all_motions_to_set_aside.pop(0)[0]).pages)
656-
for f in all_motions_to_set_aside:
657-
compiled.addpages(PdfReader(f[0]).pages)
658-
659-
compiled.addpages(PdfReader(osp_file_info[0]).pages)
660-
661-
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
662-
652+
file_paths = [f[0] for f in all_motions_to_set_aside] + [osp_file_info[0]]
663653
comp_name = "COMPILED.pdf"
664654
comp_path = path.join(temp_dir, comp_name)
665-
compiled.write(comp_path)
655+
FormFilling.compile_pdfs(file_paths, comp_path)
666656
zip_file.write(comp_path, comp_name)
667657

668658

@@ -673,6 +663,31 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
673663

674664
return zip_path, zip_file_name
675665

666+
@staticmethod
667+
def rename_fields(reader: PdfReader, start_index: int) -> int:
668+
acro_form = reader.Root.AcroForm
669+
if not acro_form or not acro_form.Fields:
670+
return 0
671+
fields = acro_form.Fields
672+
for i, field in enumerate(fields):
673+
if field.get(PdfName('T')):
674+
old_name = field[PdfName('T')].to_unicode()
675+
new_name = f"{old_name}_{start_index + i}"
676+
field[PdfName('T')] = new_name
677+
return len(fields)
678+
679+
@staticmethod
680+
def compile_pdfs(file_paths: List[str], output_path: str) -> None:
681+
compiled = PdfWriter()
682+
start_index = 0
683+
for file_path in file_paths:
684+
reader = PdfReader(file_path)
685+
field_count = FormFilling.rename_fields(reader, start_index)
686+
start_index += field_count
687+
compiled.addpages(reader.pages)
688+
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
689+
compiled.write(output_path)
690+
676691
@staticmethod
677692
def build_summary_filename(aliases):
678693
first_alias = aliases[0]

src/backend/expungeservice/form_filling_2026.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from typing import Any, Dict, List, Optional, Tuple
1818
from zipfile import ZipFile
1919

20-
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject
21-
2220
from expungeservice.form_filling import (
2321
CaseResults,
2422
DA_ADDRESSES,
@@ -124,7 +122,7 @@ def extra_mappings(self):
124122
"(defendant_name)": s.case_name,
125123
"(dob)": s.date_of_birth,
126124
"(sid_number)": s.sid or "",
127-
"(law_enforcement_agency)": "Not Known", # Per guidance, to avoid rejection
125+
"(law_enforcement_agency)": "", # Left blank, to avoid attracting attention
128126
"(arrest_date)": first_arrest_date,
129127
"(fpn_number)": "", # Leave blank
130128

@@ -325,18 +323,10 @@ def build_zip(
325323

326324
# Build compiled PDF
327325
if all_motions_to_set_aside:
328-
compiled = PdfWriter()
329-
compiled.addpages(PdfReader(all_motions_to_set_aside.pop(0)[0]).pages)
330-
for f in all_motions_to_set_aside:
331-
compiled.addpages(PdfReader(f[0]).pages)
332-
333-
compiled.addpages(PdfReader(osp_file_info[0]).pages)
334-
335-
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
336-
326+
file_paths = [f[0] for f in all_motions_to_set_aside] + [osp_file_info[0]]
337327
comp_name = "COMPILED.pdf"
338328
comp_path = path.join(temp_dir, comp_name)
339-
compiled.write(comp_path)
329+
OldFormFilling.compile_pdfs(file_paths, comp_path)
340330
zip_file.write(comp_path, comp_name)
341331

342332
# Add summary PDF

src/backend/expungeservice/waiver_form_filling.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from expungeservice.models.record_summary import RecordSummary
1212
from expungeservice.models.case import Case
13-
from expungeservice.form_filling import DA_ADDRESSES
13+
from expungeservice.form_filling import DA_ADDRESSES, FormFilling
1414

1515
def wrap_text(text):
1616
text = re.sub(r'\r\n?|\n', ' ', text)
@@ -84,6 +84,7 @@ def build_zip(
8484
zip_path = path.join(mkdtemp(), zip_file_name)
8585
zip_file = ZipFile(zip_path, "w")
8686

87+
all_waiver_files = []
8788
for case in record_summary.record.cases:
8889
if (
8990
case.summary.balance_due_in_cents > 0
@@ -92,6 +93,13 @@ def build_zip(
9293
case_data = CaseData(case, user_information_dict, waiver_information_dict)
9394
file_info = WaiverFormFilling._create_and_write_pdf(case_data, temp_dir)
9495
zip_file.write(*file_info[0:2])
96+
all_waiver_files.append(file_info)
97+
98+
if all_waiver_files:
99+
file_paths = [f[0] for f in all_waiver_files]
100+
comp_path = path.join(temp_dir, "COMPILED_FINES_AND_FEES.pdf")
101+
FormFilling.compile_pdfs(file_paths, comp_path)
102+
zip_file.write(comp_path, "COMPILED_FINES_AND_FEES.pdf")
95103

96104
zip_file.close()
97105

-284 KB
Binary file not shown.
-299 KB
Binary file not shown.
-169 KB
Binary file not shown.
-153 KB
Binary file not shown.
125 KB
Binary file not shown.
Binary file not shown.
-299 KB
Binary file not shown.

0 commit comments

Comments
 (0)