diff --git a/docassemble/AssemblyLine/al_document.py b/docassemble/AssemblyLine/al_document.py index 947d0e0e..2fa38452 100644 --- a/docassemble/AssemblyLine/al_document.py +++ b/docassemble/AssemblyLine/al_document.py @@ -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`, @@ -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: diff --git a/docassemble/AssemblyLine/data/questions/test_bundle_parity.yml b/docassemble/AssemblyLine/data/questions/test_bundle_parity.yml index ec33ba93..bc30cede 100644 --- a/docassemble/AssemblyLine/data/questions/test_bundle_parity.yml +++ b/docassemble/AssemblyLine/data/questions/test_bundle_parity.yml @@ -16,7 +16,9 @@ objects: filename="the_bundle", elements=[ the_doc - ] + ], + default_parity="even", + enabled=True ) - odd_bundle: ALDocumentBundle.using( title="Even bundle", @@ -24,7 +26,29 @@ objects: 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 ) --- @@ -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") } \ No newline at end of file + # 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() } \ No newline at end of file