Skip to content

Commit

Permalink
#828, allow default bundle parity
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed Mar 25, 2024
1 parent e9a1f22 commit 1d3aa0f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
9 changes: 8 additions & 1 deletion docassemble/AssemblyLine/al_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,7 @@ class ALDocumentBundle(DAList):
enabled (bool, optional): Determines if the bundle is active. Defaults to True.
auto_gather (bool, optional): Automatically gathers attributes. Defaults to False.
gathered (bool, optional): Specifies if attributes have been gathered. Defaults to True.
default_parity (Optional[Literal["even", "odd"]]): Default parity to enforce on the PDF. Defaults to None.
Examples:
Given three documents: `Cover page`, `Main motion form`, and `Notice of Interpreter Request`,
Expand Down Expand Up @@ -1575,7 +1576,13 @@ def as_pdf(
pdf.title = self.title
setattr(self.cache, safe_key, pdf)

if ensure_parity:
if hasattr(self, "default_parity") and not ensure_parity:
ensure_parity = self.default_parity

if ensure_parity not in [None, "even", "odd"]:
raise ValueError("ensure_parity must be either 'even', 'odd' or None")

if ensure_parity: # Check for odd/even requirement
if pdf_page_parity(pdf.path()) == ensure_parity:
return pdf
else:
Expand Down
38 changes: 35 additions & 3 deletions docassemble/AssemblyLine/data/questions/test_bundle_parity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,39 @@ objects:
filename="the_bundle",
elements=[
the_doc
]
],
default_parity="even",
enabled=True
)
- odd_bundle: ALDocumentBundle.using(
title="Even bundle",
filename="the_bundle",
elements=[
the_doc,
the_doc
]
],
enabled=True
)
- bundle_with_default: ALDocumentBundle.using(
title="Even bundle",
filename="the_bundle",
elements=[
the_doc
],
default_parity="even",
enabled=True
)

---
objects:
- bundle_of_bundles: ALDocumentBundle.using(
title="Bundle of bundles",
filename="the_bundle",
elements=[
even_bundle,
bundle_with_default
],
enabled=True
)

---
Expand All @@ -42,6 +66,14 @@ mandatory: True
question: |
Download
subquestion: |
# Should be even
${ even_bundle.as_pdf(ensure_parity="even") }
${ odd_bundle.as_pdf(ensure_parity="odd") }
# should be odd
${ odd_bundle.as_pdf(ensure_parity="odd") }
# should be even
${ bundle_with_default.as_pdf() }
# Should be even
${ bundle_of_bundles.as_pdf() }

0 comments on commit 1d3aa0f

Please sign in to comment.