Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summary report added to expungement packet #1756

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 4 additions & 34 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,33 +452,6 @@ def extra_mappings(self):
}


class SUMMARY_REPORT:
def __init__(self, path: str):
self.writer = PdfWriter()
try:
print(stat(path))
self._pdf = PdfReader(path)
print("file opened by reader")
except Exception as e:
with open(path, 'wb') as f:
self.writer.write(f)
print(e)

self._pdf = f

def add_text(self, markdown: bytes):
_pdf = PdfReader(fdata=markdown)
self.writer.addpages(_pdf.pages)

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

trailer = self.writer.trailer
trailer.Root.AcroForm = self._pdf.Root.AcroForm

self.writer.write(path, trailer=trailer)


class PDF:
BUTTON_TYPE = "/Btn"
BUTTON_ON = PdfName("On")
Expand Down Expand Up @@ -647,8 +620,8 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
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)
summary_report = FormFilling._create_and_write_summary_pdf(summary_filename, summary, temp_dir)
zip_file.write(*summary_report)

zip_file.close()

Expand Down Expand Up @@ -733,13 +706,10 @@ def _create_pdf(source_data: UserInfo, validate_initial_pdf_state=False) -> PDF:

@staticmethod
def _create_and_write_summary_pdf(file_name: str, markdown: bytes, temp_dir: str):
source_dir = path.join(Path(__file__).parent, "files")
pdf_path = path.join(source_dir, file_name)
pdf = SUMMARY_REPORT(pdf_path)
pdf = PdfWriter().addpages(PdfReader(fdata = markdown).pages)

pdf.add_text(markdown)
write_file_path, write_file_name = path.join(temp_dir, file_name), file_name
pdf.writer.write(write_file_path)
pdf.write(write_file_path)
return write_file_path, write_file_name


Expand Down
2 changes: 1 addition & 1 deletion src/backend/tests/test_form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_normal_conviction_uses_multnomah_conviction_form():
with ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(temp_dir)
for _root, _dir, files in os.walk(temp_dir):
assert len(files) == 1
assert len(files) == 2


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