Skip to content

Commit eeb7921

Browse files
Adds a maximum size per document param
Needs, since Tyler lets courts restrict individual document uploads, as well as the envelope as a whole, so adds a `maximum_size_per_doc` parameter that acts per document (which is needed so folks don't upload one file within the limit and then another one out of the limit on the second screen, which would be rejected by Tyler; this has happened in production recently).
1 parent f787e85 commit eeb7921

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

docassemble/AssemblyLine/al_document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,7 @@ class ALExhibitList(DAList):
28772877
28782878
Attributes:
28792879
maximum_size (int): The maximum allowed size in bytes of the entire document.
2880+
maximum_size_per_doc (int): The maximum allowed size in bytes per document in the list
28802881
auto_label (bool): If True, automatically numbers exhibits for cover page and table of contents. Defaults to True.
28812882
auto_labeler (Callable): An optional function or lambda to transform the exhibit's index to a label.
28822883
Uses A..Z labels by default.
@@ -3075,6 +3076,7 @@ class ALExhibitDocument(ALDocument):
30753076
auto_ocr: bool
30763077
bates_prefix: str
30773078
maximum_size: int
3079+
maximum_size_per_doc: int
30783080
suffix_to_append: str
30793081
exhibits: ALExhibitList
30803082
table_of_contents: DAFile
@@ -3099,8 +3101,13 @@ def init(self, *pargs, **kwargs) -> None:
30993101
else:
31003102
self.include_exhibit_cover_pages = True
31013103
self.exhibits.include_exhibit_cover_pages = True
3104+
if hasattr(self, "maximum_size_per_doc"):
3105+
self.exhibits.maximum_size_per_doc = self.maximum_size_per_doc
31023106
if hasattr(self, "maximum_size"):
31033107
self.exhibits.maximum_size = self.maximum_size
3108+
if not hasattr(self, "maximum_size_per_doc"):
3109+
self.maximum_size_per_doc = self.maximum_size
3110+
self.exhibits.maximum_size_per_doc = self.maximum_size
31043111
if hasattr(self, "include_table_of_contents"):
31053112
self.exhibits.include_table_of_contents = self.include_table_of_contents
31063113
else:

docassemble/AssemblyLine/data/questions/ql_baseline.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,9 @@ validation code: |
18821882
if hasattr(x, 'maximum_size'):
18831883
if full_size > x.maximum_size:
18841884
validation_error(f"Upload a file smaller than {humanize.naturalsize(x.maximum_size)}")
1885+
if hasattr(x, 'maximum_size_per_doc'):
1886+
if full_size > x.maximum_size_per_doc:
1887+
validation_error(f"Upload a file smaller than {humanize.naturalsize(x.maximum_size)}")
18851888
try:
18861889
pdf_concatenate(x[0].pages)
18871890
except:
@@ -1910,6 +1913,9 @@ fields:
19101913
"image/png, image/jpeg, .doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,.pdf"
19111914
validation code: |
19121915
this_doc_size = sum(a_page.size_in_bytes() for a_page in x[i].pages)
1916+
if hasattr(x, 'maximum_size_per_doc'):
1917+
if this_doc_size > x.maximum_size_per_doc:
1918+
validation_error(f"This document should be smaller than {humanize.naturalsize(x.maximum_size_per_doc)}")
19131919
if this_doc_size > (15 * 1024 * 1024):
19141920
validation_error("Upload a file smaller than 15 MB.")
19151921
if hasattr(x, 'maximum_size'):
@@ -1930,9 +1936,19 @@ question: |
19301936
subquestion: |
19311937
You have uploaded ${ x[i].pages.num_pages() } pages so far.
19321938
1939+
<% current_doc_size = sum(ap.size_in_bytes() for ap in x[i].pages.complete_elements()) %>
1940+
% if hasattr(x, 'maximum_size_per_doc'):
1941+
This document must be smaller than ${ humanize.naturalsize(x.maximum_size_per_doc) }.
1942+
% if not hasattr(x, 'maximum_size') or x.maximum_size_per_doc - current_doc_size < x.maximum_size - x.size_in_bytes() - current_doc_size:
1943+
You can upload ${ humanize.naturalsize(x.maximum_size_per_doc - current_doc_size) } more.
1944+
% else:
1945+
You can upload ${ humanize.naturalsize(x.maximum_size - x.size_in_bytes() - current_doc_size) } more.
1946+
% endif
1947+
% endif
1948+
19331949
% if hasattr(x, 'maximum_size'):
19341950
The total size of all exhibits must be less than ${ humanize.naturalsize(x.maximum_size) }.
1935-
You can upload ${ humanize.naturalsize(x.maximum_size - x.size_in_bytes() - sum(ap.size_in_bytes() for ap in x[i].pages.complete_elements()))} more.
1951+
You can upload ${ humanize.naturalsize(x.maximum_size - x.size_in_bytes() - current_doc_size) } more.
19361952
% endif
19371953
19381954
${ collapse_template(x[i].in_progress_template )}
@@ -1968,11 +1984,16 @@ fields:
19681984
"image/png, image/jpeg, .doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,.pdf"
19691985
validation code: |
19701986
page_size = x[i].pages[j].size_in_bytes()
1987+
this_doc_size = sum(a_page.size_in_bytes() for a_page in x[i].pages.complete_elements()) + page_size
1988+
log(f"length of completed elements: {len(x[i].pages.complete_elements())}")
1989+
if hasattr(x, 'maximum_size_per_doc'):
1990+
if this_doc_size > x.maximum_size_per_doc:
1991+
suggested_size = x.maximum_size_per_doc - (this_doc_size - page_size)
1992+
validation_error(f"This document must be smaller than {humanize.naturalsize(x.maximum_size_per_doc) }. Upload a file smaller than {humanize.naturalsize(suggested_size)}.")
1993+
19711994
if page_size > (15 * 1024 * 1024):
19721995
validation_error("Upload a file smaller than 15 MB.")
19731996
if hasattr(x, 'maximum_size'):
1974-
# this_doc_size already includes `page_size`
1975-
this_doc_size = sum(a_page.size_in_bytes() for a_page in x[i].pages.complete_elements())
19761997
full_size = x.size_in_bytes() + this_doc_size
19771998
if full_size > x.maximum_size:
19781999
suggested_size = x.maximum_size - (full_size - page_size)

0 commit comments

Comments
 (0)