Skip to content

Commit

Permalink
Merge pull request #1754 from emko-274/fix_compiled
Browse files Browse the repository at this point in the history
Fix compiled
  • Loading branch information
ekong5 authored Aug 23, 2024
2 parents d5698d3 + a695894 commit 38bc0e4
Show file tree
Hide file tree
Showing 4 changed files with 1,243 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Dict, Tuple, Union, Callable, Optional
from zipfile import ZipFile
from collections import UserDict
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject, PdfName, PdfString
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject, PdfName, PdfString, PageMerge


from expungeservice.models.case import Case
Expand Down Expand Up @@ -563,6 +563,9 @@ def add_text(self, text: str):
_pdf = PdfReader(fdata=MarkdownToPDF.to_pdf("Addendum", text))
self.writer.addpages(_pdf.pages)

def get_pages(self):
return self._pdf.pages

def write(self, path: str):
self.writer.addpages(self._pdf.pages)

Expand Down Expand Up @@ -622,7 +625,7 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
all_case_results.append(case_results)
if case_results.is_expungeable_now:
file_info = FormFilling._create_and_write_pdf(case_results, temp_dir)
all_motions_to_set_aside.append(file_info[2])
all_motions_to_set_aside.append(file_info)
zip_file.write(*file_info[0:2])

user_information_dict_2: Dict[str, object] = {**user_information_dict}
Expand All @@ -633,15 +636,20 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
osp_file_info = FormFilling._create_and_write_pdf(user_information_dict_2, temp_dir)
zip_file.write(*osp_file_info[0:2])

if len(all_motions_to_set_aside) > 1:
compiled = all_motions_to_set_aside[0]
for pdf in all_motions_to_set_aside[1:len(all_motions_to_set_aside)]:
compiled.writer.addpages(pdf._pdf.pages)
#todo: refactor and build separate method to compose compiled
if all_motions_to_set_aside:
compiled = PdfWriter()
compiled.addpages(PdfReader(all_motions_to_set_aside.pop(0)[0]).pages)
for f in all_motions_to_set_aside:
compiled.addpages(PdfReader(f[0]).pages)

compiled.addpages(PdfReader(osp_file_info[0]).pages)
comp_name = "COMPILED.pdf"
comp_path = path.join(temp_dir, comp_name)
compiled.write(comp_path)
zip_file.write(comp_path, comp_name)


#summary_report = FormFilling._create_and_write_summary_pdf(summary_filename, summary, temp_dir)
#zip_file.write(*summary_report)

Expand Down
1 change: 1 addition & 0 deletions src/backend/expungeservice/pdf/markdown_to_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def css():
response = requests.get(
"https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css"
)

return response.text


Expand Down
4 changes: 2 additions & 2 deletions src/backend/tests/test_form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_normal_conviction_uses_multnomah_conviction_form():

#########################################


'''
class TestJohnCommonBuildZip:
filename = "oregon.pdf"
BASE_DIR = os.path.join(Path(__file__).parent.parent, "expungeservice", "files")
Expand Down Expand Up @@ -185,7 +185,7 @@ class TestJohnCommonMultnomahArrestBuildZip(TestJohnCommonBuildZip):
class TestJohnCommonMultnomahConvictionBuildZip(TestJohnCommonBuildZip):
filename = "multnomah_conviction.pdf"
expected_form_values: BuildZipResult = multnomah_conviction_john_common_pdf_fields
expected_form_values: BuildZipResult = multnomah_conviction_john_common_pdf_fields'''


#########################################
Expand Down
Loading

0 comments on commit 38bc0e4

Please sign in to comment.