Skip to content

Commit 462cabb

Browse files
Restrict max size per document
Uses the new `maximum_size_per_doc` param to the ALExhibits object to limit the size of individual documents. In order to attempt to account for the OCR'd layer on the PDF (which is added after the user uploads their files), it makes the limit stricter by 1 MB. Might not be enough, but it gets more difficult when the document that is upload isn't the exact same one that we submit. Depends on SuffolkLITLab/docassemble-AssemblyLine#1002.
1 parent 13fee10 commit 462cabb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

docassemble/MotionToStayEviction/data/questions/SP6A.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ code: |
149149
# Uses max_size from Tyler
150150
if: can_check_efile
151151
objects:
152-
- exhibit_doc: ALExhibitDocument.using(title="Exhibits", filename='exhibits', bates_prefix="EX-", include_exhibit_cover_page=True, include_table_of_contents=True, add_page_numbers=True, auto_ocr=True, maximum_size=max_total_exhibit_size)
152+
- exhibit_doc: ALExhibitDocument.using(title="Exhibits", filename='exhibits', bates_prefix="EX-", include_exhibit_cover_page=True, include_table_of_contents=True, add_page_numbers=True, auto_ocr=True, maximum_size=max_total_exhibit_size, maximum_size_per_doc=max_per_file)
153153
---
154154
if: not can_check_efile
155155
objects:
@@ -1074,8 +1074,16 @@ fields:
10741074
show if: x.has_exhibits
10751075
validation code: |
10761076
if x.has_exhibits:
1077-
if sum(exhibit.size_in_bytes() for exhibit in x[0].pages) > (15 * 1024 * 1024):
1077+
this_doc_size = sum(exhibit.size_in_bytes() for exhibit in x[0].pages)
1078+
if hasattr(x, 'maximum_size_per_doc'):
1079+
if this_doc_size > x.maximum_size_per_doc:
1080+
validation_error(f"This document should be smaller than {humanize.naturalsize(x.maximum_size_per_doc)}")
1081+
if this_doc_size > (15 * 1024 * 1024):
10781082
validation_error("Upload a file smaller than 15 MB.")
1083+
if hasattr(x, 'maximum_size'):
1084+
if this_doc_size > x.maximum_size:
1085+
suggested_size = x.maximum_size - this_doc_size
1086+
validation_error(f"All exhibits combined must be smaller than {humanize.naturalsize(x.maximum_size)}. Upload a file smaller than {humanize.naturalsize(suggested_size)}.")
10791087
try:
10801088
pdf_concatenate(x[0].pages)
10811089
except:

docassemble/MotionToStayEviction/data/questions/efiling.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,15 @@ only sets:
9191
- max_mb_per_file
9292
code: |
9393
allowed_sizes = get_max_allowed_sizes(proxy_conn, court_id)
94+
one_mb = 1024 * 1024
9495
if allowed_sizes:
9596
max_mb_per_file = allowed_sizes[0] / 1024 / 1024
96-
max_total_exhibit_size = allowed_sizes[1]
97+
if allowed_size[0] > one_mb:
98+
# OCR will increase file sizes a bit, so save some room
99+
max_per_file = allowed_sizes[0] - one_mb
100+
else:
101+
max_per_file = allowed_sizes[0]
102+
max_total_exhibit_size = allowed_sizes[1] - one_mb
97103
else:
98104
max_mb_per_file = 15
99105
max_total_exhibit_size = 50 * 1024 * 1024

0 commit comments

Comments
 (0)